From: Daniel Theophanes Date: Fri, 11 Jan 2019 22:20:41 +0000 (-0800) Subject: database/sql: fix logic for pulling a Conn from DB X-Git-Tag: go1.12rc1~79 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=70931c087b7ceb660aa969382b8c273efba63426;p=gostls13.git 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index b0353ab4dc..38a173adba 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -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