Skip to content

Commit be8468e

Browse files
committed
fix race condition when context is canceled (#1562)
Fix #1559. (cherry picked from commit d86c452)
1 parent 1e75613 commit be8468e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Diff for: connection.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (mc *mysqlConn) Close() (err error) {
137137
}
138138

139139
mc.cleanup()
140-
140+
mc.clearResult()
141141
return
142142
}
143143

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

153153
// Makes cleanup idempotent
154154
close(mc.closech)
155-
if mc.netConn == nil {
155+
nc := mc.netConn
156+
if nc == nil {
156157
return
157158
}
158-
if err := mc.netConn.Close(); err != nil {
159+
if err := nc.Close(); err != nil {
159160
mc.log(err)
160161
}
161-
mc.clearResult()
162+
// This function can be called from multiple goroutines.
163+
// So we can not mc.clearResult() here.
164+
// Caller should do it if they are in safe goroutine.
162165
}
163166

164167
func (mc *mysqlConn) error() error {

0 commit comments

Comments
 (0)