]> Cypherpunks repositories - gostls13.git/commit
database/sql: avoid deadlock waiting for connections
authorChris Hines <chris.cs.guy@gmail.com>
Mon, 14 Sep 2015 07:44:56 +0000 (03:44 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 16 Oct 2015 15:17:03 +0000 (15:17 +0000)
commit6de40099c88048c95df40c873e89b0e31f70ac24
treed5fde34e8e15ef68a5aaea1320f49265275e3cbf
parent19aa4209aebce5deaf485268e210ed3fc29cacd5
database/sql: avoid deadlock waiting for connections

Previously with db.maxOpen > 0, db.maxOpen+n failed connection attempts
started concurrently could result in a deadlock. DB.conn and
DB.openNewConnection did not trigger the DB.connectionOpener go routine
after a failed connection attempt. This omission could leave go routines
waiting for DB.connectionOpener forever.

In addition the logic to track the state of the pool was inconsistent.
db.numOpen was sometimes incremented optimistically and sometimes not.
This change harmonizes the logic and eliminates the db.pendingOpens
variable, making the logic easier to understand and maintain.

Fixes #10886

Change-Id: I983c4921a3dacfbd531c3d7f8d2da8a592e9922a
Reviewed-on: https://go-review.googlesource.com/14547
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/database/sql/fakedb_test.go
src/database/sql/sql.go
src/database/sql/sql_test.go