Skip to content

Commit c855c26

Browse files
authored
Merge pull request #718 from D3Hunter/fix
use background as base ctx in context.WithTimeout
2 parents b78bcee + 845999a commit c855c26

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

replication/binlogsyncer.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (b *BinlogSyncer) close() {
210210
// Use a new connection to kill the binlog syncer
211211
// because calling KILL from the same connection
212212
// doesn't actually disconnect it.
213-
c, err := b.newConnection()
213+
c, err := b.newConnection(context.Background())
214214
if err == nil {
215215
b.killConnection(c, b.lastConnectionID)
216216
c.Close()
@@ -241,7 +241,7 @@ func (b *BinlogSyncer) registerSlave() error {
241241
}
242242

243243
var err error
244-
b.c, err = b.newConnection()
244+
b.c, err = b.newConnection(b.ctx)
245245
if err != nil {
246246
return errors.Trace(err)
247247
}
@@ -864,18 +864,18 @@ func (b *BinlogSyncer) LastConnectionID() uint32 {
864864
return b.lastConnectionID
865865
}
866866

867-
func (b *BinlogSyncer) newConnection() (*client.Conn, error) {
867+
func (b *BinlogSyncer) newConnection(ctx context.Context) (*client.Conn, error) {
868868
var addr string
869869
if b.cfg.Port != 0 {
870870
addr = net.JoinHostPort(b.cfg.Host, strconv.Itoa(int(b.cfg.Port)))
871871
} else {
872872
addr = b.cfg.Host
873873
}
874874

875-
ctx, cancel := context.WithTimeout(b.ctx, time.Second*10)
875+
timeoutCtx, cancel := context.WithTimeout(ctx, time.Second*10)
876876
defer cancel()
877877

878-
return client.ConnectWithDialer(ctx, "", addr, b.cfg.User, b.cfg.Password,
878+
return client.ConnectWithDialer(timeoutCtx, "", addr, b.cfg.User, b.cfg.Password,
879879
"", b.cfg.Dialer, func(c *client.Conn) {
880880
c.SetTLSConfig(b.cfg.TLSConfig)
881881
})

0 commit comments

Comments
 (0)