From 733aefd06e5cf708637308a4ad7a048aa97db5cd Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 28 Jun 2016 12:06:08 -0700 Subject: database/sql: deflake TestPendingConnsAfterErr and fix races, panics TestPendingConnsAfterErr only cared that things didn't deadlock, so 5 seconds is a sufficient timer. We don't need 100 milliseconds. I was able to reproduce with a tiny (5 nanosecond) timeout value, instead of 100 milliseconds. In the process of testing with -race and a high -count= value, I noticed several data races and panics (sendings on a closed channel) which are also fixed in this change. Fixes #15684 Change-Id: Ib4605fcc0f296e658cb948352ed642b801cb578c Reviewed-on: https://go-review.googlesource.com/24550 Reviewed-by: Marko Tiikkaja Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Andrew Gerrand --- src/database/sql/sql.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/database/sql/sql.go') diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index e7482a8e2f..09de1c34e8 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -718,6 +718,9 @@ func (db *DB) maybeOpenNewConnections() { for numRequests > 0 { db.numOpen++ // optimistically numRequests-- + if db.closed { + return + } db.openerCh <- struct{}{} } } @@ -915,6 +918,9 @@ func (db *DB) putConn(dc *driverConn, err error) { // If a connRequest was fulfilled or the *driverConn was placed in the // freeConn list, then true is returned, otherwise false is returned. func (db *DB) putConnDBLocked(dc *driverConn, err error) bool { + if db.closed { + return false + } if db.maxOpen > 0 && db.numOpen > db.maxOpen { return false } -- cgit v1.3