From 56d5b78589b87922f58ab8d066397995224201a6 Mon Sep 17 00:00:00 2001 From: D3Hunter Date: Mon, 18 Jul 2022 17:10:00 +0800 Subject: [PATCH 1/2] fix --- replication/binlogsyncer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/replication/binlogsyncer.go b/replication/binlogsyncer.go index 8a8c2fd22..d6d9e94dc 100644 --- a/replication/binlogsyncer.go +++ b/replication/binlogsyncer.go @@ -872,7 +872,7 @@ func (b *BinlogSyncer) newConnection() (*client.Conn, error) { addr = b.cfg.Host } - ctx, cancel := context.WithTimeout(b.ctx, time.Second*10) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() return client.ConnectWithDialer(ctx, "", addr, b.cfg.User, b.cfg.Password, From 845999ac4558c524c2607d449ca95533ec4cf0f9 Mon Sep 17 00:00:00 2001 From: D3Hunter Date: Mon, 18 Jul 2022 17:20:06 +0800 Subject: [PATCH 2/2] use b.ctx for normal conn --- replication/binlogsyncer.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/replication/binlogsyncer.go b/replication/binlogsyncer.go index d6d9e94dc..f1f44a4eb 100644 --- a/replication/binlogsyncer.go +++ b/replication/binlogsyncer.go @@ -210,7 +210,7 @@ func (b *BinlogSyncer) close() { // Use a new connection to kill the binlog syncer // because calling KILL from the same connection // doesn't actually disconnect it. - c, err := b.newConnection() + c, err := b.newConnection(context.Background()) if err == nil { b.killConnection(c, b.lastConnectionID) c.Close() @@ -241,7 +241,7 @@ func (b *BinlogSyncer) registerSlave() error { } var err error - b.c, err = b.newConnection() + b.c, err = b.newConnection(b.ctx) if err != nil { return errors.Trace(err) } @@ -864,7 +864,7 @@ func (b *BinlogSyncer) LastConnectionID() uint32 { return b.lastConnectionID } -func (b *BinlogSyncer) newConnection() (*client.Conn, error) { +func (b *BinlogSyncer) newConnection(ctx context.Context) (*client.Conn, error) { var addr string if b.cfg.Port != 0 { addr = net.JoinHostPort(b.cfg.Host, strconv.Itoa(int(b.cfg.Port))) @@ -872,10 +872,10 @@ func (b *BinlogSyncer) newConnection() (*client.Conn, error) { addr = b.cfg.Host } - ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) + timeoutCtx, cancel := context.WithTimeout(ctx, time.Second*10) defer cancel() - return client.ConnectWithDialer(ctx, "", addr, b.cfg.User, b.cfg.Password, + return client.ConnectWithDialer(timeoutCtx, "", addr, b.cfg.User, b.cfg.Password, "", b.cfg.Dialer, func(c *client.Conn) { c.SetTLSConfig(b.cfg.TLSConfig) })