Skip to content

Commit 70931c0

Browse files
kardianosbradfitz
authored andcommitted
database/sql: fix logic for pulling a Conn from DB
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 #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]>
1 parent 4e8aaf6 commit 70931c0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/database/sql/sql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ func (db *DB) Conn(ctx context.Context) (*Conn, error) {
16981698
}
16991699
}
17001700
if err == driver.ErrBadConn {
1701-
dc, err = db.conn(ctx, cachedOrNewConn)
1701+
dc, err = db.conn(ctx, alwaysNewConn)
17021702
}
17031703
if err != nil {
17041704
return nil, err

0 commit comments

Comments
 (0)