1
0
mirror of https://github.com/golang/go synced 2024-11-25 10:17:57 -07:00
go/src/database/sql
Nic Klaassen 08707d66c3 database/sql: fix panic with concurrent Conn and Close
The current implementation has a panic when the database is closed
concurrently with a new connection attempt.

connRequestSet.CloseAndRemoveAll sets connRequestSet.s to a nil slice.
If this happens between calls to connRequestSet.Add and
connRequestSet.Delete, there is a panic when trying to write to the nil
slice. This is sequence is likely to occur in DB.conn, where the mutex
is released between calls to db.connRequests.Add and
db.connRequests.Delete

This change updates connRequestSet.CloseAndRemoveAll to set the curIdx
to -1 for all pending requests before setting its internal slice to nil.
CloseAndRemoveAll already iterates the full slice to close all the request
channels. It seems appropriate to set curIdx to -1 before deleting the
slice for 3 reasons:
1. connRequestSet.deleteIndex also sets curIdx to -1
2. curIdx will not be relevant to anything after the slice is set to nil
3. connRequestSet.Delete already checks for negative indices

Fixes #68949

Change-Id: I6b7ebc5a71b67322908271d13865fa12f2469b87
GitHub-Last-Rev: 7d2669155b
GitHub-Pull-Request: golang/go#68953
Reviewed-on: https://go-review.googlesource.com/c/go/+/607238
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Commit-Queue: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-08-24 00:26:08 +00:00
..
driver database/sql/driver: fix name in comment 2024-07-11 15:01:00 +00:00
convert_test.go database/sql: avoid clobbering driver-owned memory in RawBytes 2024-04-10 20:23:22 +00:00
convert.go all: document legacy //go:linkname for final round of modules 2024-05-29 17:58:53 +00:00
ctxutil.go
doc.txt database/sql: fix typo in comment 2024-03-22 06:48:08 +00:00
example_cli_test.go all: fix some lint issues 2022-05-08 17:27:54 +00:00
example_service_test.go database/sql: add error check 2024-02-28 20:21:26 +00:00
example_test.go
fakedb_test.go database/sql: use slices to simplify the code 2024-04-01 12:38:07 +00:00
sql_test.go database/sql: fix panic with concurrent Conn and Close 2024-08-24 00:26:08 +00:00
sql.go database/sql: fix panic with concurrent Conn and Close 2024-08-24 00:26:08 +00:00