Skip to content

Commit

Permalink
fix race condition when context is canceled (go-sql-driver#1562)
Browse files Browse the repository at this point in the history
Fix go-sql-driver#1559.

(cherry picked from commit d86c452)
  • Loading branch information
methane committed Mar 17, 2024
1 parent 33b7747 commit 8a24bdf
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (mc *mysqlConn) Close() (err error) {
}

mc.cleanup()

mc.clearResult()
return
}

Expand All @@ -147,13 +147,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 {
mc.cfg.Logger.Print(err)
if err := nc.Close(); err != nil {
mc.log(err)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / lint

mc.log undefined (type *mysqlConn has no field or method log) (compile)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / lint

mc.log undefined (type *mysqlConn has no field or method log) (compile)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21, 8.0)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21, mariadb-10.6)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21, mariadb-10.3)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21, 5.6)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.20, 8.1)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21, 8.1)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21, 5.7)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21, mariadb-10.5)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21, mariadb-10.4)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21, mariadb-10.11)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.21, 5.7)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.21, 8.1)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.21, 5.6)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.21, 8.0)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.21, mariadb-10.6)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.21, mariadb-10.4)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.21, mariadb-10.5)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.21, mariadb-10.11)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.21, mariadb-10.5)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.21, mariadb-10.3)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.21, 5.6)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.21, mariadb-10.11)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.21, 8.1)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.21, 5.7)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.21, 8.0)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.21, mariadb-10.3)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.21, mariadb-10.4)

mc.log undefined (type *mysqlConn has no field or method log)

Check failure on line 155 in connection.go

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.21, mariadb-10.6)

mc.log undefined (type *mysqlConn has no field or method log)
}
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 8a24bdf

Please sign in to comment.