From d84dee069a534bd7a35ec4062a92a04ce9c2806e Mon Sep 17 00:00:00 2001 From: Daniel Theophanes Date: Wed, 8 Feb 2017 21:38:51 -0800 Subject: [PATCH] [release-branch.go1.8] database/sql: ensure driverConns are closed if not returned to pool Previously if a connection was requested but timed out during the request and when acquiring the db.Lock the connection request is fulfilled and the request is unable to be returned to the connection pool, then then driver connection would not be closed. No tests were added or modified because I was unable to determine how to trigger this situation without something invasive. Change-Id: I9d4dc680e3fdcf63d79d212174a5b8b313f363f1 Reviewed-on: https://go-review.googlesource.com/36641 Reviewed-by: Russ Cox Reviewed-on: https://go-review.googlesource.com/36714 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/database/sql/sql.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index 1e27b17cf9..c016681fca 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -939,14 +939,14 @@ func (db *DB) conn(ctx context.Context, strategy connReuseStrategy) (*driverConn // on it after removing. db.mu.Lock() delete(db.connRequests, reqKey) + db.mu.Unlock() select { default: case ret, ok := <-req: if ok { - db.putConnDBLocked(ret.conn, ret.err) + db.putConn(ret.conn, ret.err) } } - db.mu.Unlock() return nil, ctx.Err() case ret, ok := <-req: if !ok { -- 2.48.1