Skip to content

Commit

Permalink
database/sql: ensure driverConns are closed if not returned to pool
Browse files Browse the repository at this point in the history
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 <rsc@golang.org>
  • Loading branch information
kardianos authored and rsc committed Feb 10, 2017
1 parent 9a75443 commit a335c34
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/database/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a335c34

Please sign in to comment.