Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use background context when KILL last connection #718

Merged
merged 2 commits into from
Jul 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions replication/binlogsyncer.go
Original file line number Diff line number Diff line change
@@ -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,18 +864,18 @@ 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)))
} else {
addr = b.cfg.Host
}

ctx, cancel := context.WithTimeout(b.ctx, 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)
})