summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Theophanes <kardianos@gmail.com>2017-11-13 14:25:19 -0800
committerBrad Fitzpatrick <bradfitz@golang.org>2017-11-14 00:25:42 +0000
commitf7df55d174b886f8aea0243aa40e8debffbdffc0 (patch)
tree1771ad97eb45330e0dbf974a48104f56270dfcc4
parent4aea3e7135a1945dc183e3c0d9180cbed2ed6ba7 (diff)
downloadgo-git-f7df55d174b886f8aea0243aa40e8debffbdffc0.tar.gz
database/sql: do not leak the connectionResetter goroutine
Before terminating the connectionResetter goroutine the connection pool processes all of the connections on the channel to unlock the driverConn instances so everthing can shutdown cleanly. However the channel was never closed so the goroutine hangs on the range. Close the channel prior to ranging over it. Also prevent additional connections from being sent to the resetter after the connection pool has been closed. Fixes #22699 Change-Id: I440d2b13cbedec2e04621557f5bd0b1526933dd7 Reviewed-on: https://go-review.googlesource.com/77390 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
-rw-r--r--src/database/sql/sql.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go
index be73b5e372..252a0f6713 100644
--- a/src/database/sql/sql.go
+++ b/src/database/sql/sql.go
@@ -939,6 +939,7 @@ func (db *DB) connectionResetter(ctx context.Context) {
for {
select {
case <-ctx.Done():
+ close(db.resetterCh)
for dc := range db.resetterCh {
dc.Unlock()
}
@@ -1171,6 +1172,11 @@ func (db *DB) putConn(dc *driverConn, err error, resetSession bool) {
if putConnHook != nil {
putConnHook(db, dc)
}
+ if db.closed {
+ // Connections do not need to be reset if they will be closed.
+ // Prevents writing to resetterCh after the DB has closed.
+ resetSession = false
+ }
if resetSession {
if _, resetSession = dc.ci.(driver.ResetSessioner); resetSession {
// Lock the driverConn here so it isn't released until