Skip to content

Commit

Permalink
fix race condition when context is canceled (#1562)
Browse files Browse the repository at this point in the history
Fix #1559.
  • Loading branch information
methane authored Mar 17, 2024
1 parent 1a64773 commit d86c452
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 @@ -138,7 +138,7 @@ func (mc *mysqlConn) Close() (err error) {
}

mc.cleanup()

mc.clearResult()
return
}

Expand All @@ -153,13 +153,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 d86c452

Please sign in to comment.