Skip to content

Commit d84dee0

Browse files
kardianosrsc
authored andcommitted
[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 <[email protected]> Reviewed-on: https://go-review.googlesource.com/36714 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent f1e44a4 commit d84dee0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/database/sql/sql.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,14 +939,14 @@ func (db *DB) conn(ctx context.Context, strategy connReuseStrategy) (*driverConn
939939
// on it after removing.
940940
db.mu.Lock()
941941
delete(db.connRequests, reqKey)
942+
db.mu.Unlock()
942943
select {
943944
default:
944945
case ret, ok := <-req:
945946
if ok {
946-
db.putConnDBLocked(ret.conn, ret.err)
947+
db.putConn(ret.conn, ret.err)
947948
}
948949
}
949-
db.mu.Unlock()
950950
return nil, ctx.Err()
951951
case ret, ok := <-req:
952952
if !ok {

0 commit comments

Comments
 (0)