Skip to content

Commit

Permalink
database/sql: fix logic for pulling a Conn from DB
Browse files Browse the repository at this point in the history
The logic for pulling a database connection from the DB pool should
proceed as follows: attempt to pull either a cached connection or
new connection N times in a loop. If each connection results
in a bad connection, then create a new connection (no cache).

Previously pulling a Conn from the pool, the last step also
looked at the cache, rather then always creating a new connection.

Fixes golang#29684

Change-Id: I8f436fd9b96eb35502a620ebe8da4ab89fb06a2e
Reviewed-on: https://go-review.googlesource.com/c/157637
Reviewed-by: Brad Fitzpatrick <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
kardianos authored and bradfitz committed Jan 14, 2019
1 parent 4e8aaf6 commit 70931c0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/database/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ func (db *DB) Conn(ctx context.Context) (*Conn, error) {
}
}
if err == driver.ErrBadConn {
dc, err = db.conn(ctx, cachedOrNewConn)
dc, err = db.conn(ctx, alwaysNewConn)
}
if err != nil {
return nil, err
Expand Down

0 comments on commit 70931c0

Please sign in to comment.