Skip to content

Commit

Permalink
fix race condition when context is canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Mar 16, 2024
1 parent 8a327a3 commit e9b7c9a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,13 @@ func (mc *mysqlConn) getSystemVar(name string) ([]byte, error) {
// finish is called when the query has canceled.
func (mc *mysqlConn) cancel(err error) {
mc.canceled.Set(err)
mc.cleanup()
nc := mc.netConn
if nc != nil {
_ = nc.SetDeadline(time.Now()) // wake up pending reads/writes
// Ignore error because:
// - If the connection is already closed, thats fine.
// - If the connection return error other reasons, we can not do anything about it.
}
}

// finish is called when the query has succeeded.
Expand Down

0 comments on commit e9b7c9a

Please sign in to comment.