Skip to content

Commit

Permalink
fix race condition when context is canceled (#1565)
Browse files Browse the repository at this point in the history
Fix #1559.

(cherry picked from commit d86c452)
  • Loading branch information
methane authored Mar 17, 2024
1 parent 1e75613 commit 65395d8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (mc *mysqlConn) Close() (err error) {
}

mc.cleanup()

mc.clearResult()
return
}

Expand All @@ -152,13 +152,16 @@ func (mc *mysqlConn) cleanup() {

// Makes cleanup idempotent
close(mc.closech)
if mc.netConn == nil {
nc := mc.netConn
if nc == nil {
return
}
if err := mc.netConn.Close(); err != nil {
if err := nc.Close(); err != nil {
mc.log(err)
}
mc.clearResult()
// This function can be called from multiple goroutines.
// So we can not mc.clearResult() here.
// Caller should do it if they are in safe goroutine.
}

func (mc *mysqlConn) error() error {
Expand Down

0 comments on commit 65395d8

Please sign in to comment.