Skip to content

Commit e9b7c9a

Browse files
committed
fix race condition when context is canceled
1 parent 8a327a3 commit e9b7c9a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: connection.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,13 @@ func (mc *mysqlConn) getSystemVar(name string) ([]byte, error) {
439439
// finish is called when the query has canceled.
440440
func (mc *mysqlConn) cancel(err error) {
441441
mc.canceled.Set(err)
442-
mc.cleanup()
442+
nc := mc.netConn
443+
if nc != nil {
444+
_ = nc.SetDeadline(time.Now()) // wake up pending reads/writes
445+
// Ignore error because:
446+
// - If the connection is already closed, thats fine.
447+
// - If the connection return error other reasons, we can not do anything about it.
448+
}
443449
}
444450

445451
// finish is called when the query has succeeded.

0 commit comments

Comments
 (0)