Skip to content

Commit b28e907

Browse files
committed
replication: check hostname length
1 parent 81ff5fd commit b28e907

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

canal/config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ type Config struct {
105105
// Set Dialer
106106
Dialer client.Dialer
107107

108-
// Set Localhost
108+
// Set the hostname that is used when registering as replica. This is similar to `report_host` in MySQL.
109+
// This will be truncated if it is longer than 255 characters.
109110
Localhost string
110111

111112
// EventCacheCount is the capacity of the BinlogStreamer internal event channel.

replication/binlogsyncer.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,17 @@ func (b *BinlogSyncer) writeBinlogDumpMariadbGTIDCommand(gset mysql.GTIDSet) err
573573
return b.writeBinlogDumpCommand(mysql.Position{Name: "", Pos: 0})
574574
}
575575

576-
// localHostname returns the hostname that register slave would register as.
576+
// localHostname returns the hostname that register replica would register as.
577+
// this gets truncated to 255 bytes.
577578
func (b *BinlogSyncer) localHostname() string {
578-
if len(b.cfg.Localhost) == 0 {
579-
h, _ := os.Hostname()
579+
h := b.cfg.Localhost
580+
if len(h) == 0 {
581+
h, _ = os.Hostname()
582+
}
583+
if len(h) <= 255 {
580584
return h
581585
}
582-
return b.cfg.Localhost
586+
return h[:255]
583587
}
584588

585589
func (b *BinlogSyncer) writeRegisterSlaveCommand() error {

0 commit comments

Comments
 (0)