]> Cypherpunks repositories - gostls13.git/commit
database/sql: check conn expiry when returning to pool, not when handing it out
authorDaniel Theophanes <kardianos@gmail.com>
Fri, 24 Jan 2020 02:18:39 +0000 (18:18 -0800)
committerDaniel Theophanes <kardianos@gmail.com>
Mon, 20 Apr 2020 17:41:27 +0000 (17:41 +0000)
commitb2cff7e091ca1f59ceb77c4dd3acaf0c150b5440
treeee6c91359f1908d6bb94bdf294242a56179dd6f9
parentf8ff12d480dcfe0db17648939644d0eeec0ed0fb
database/sql: check conn expiry when returning to pool, not when handing it out

With the original connection reuse strategy, it was possible that
when a new connection was requested, the pool would wait for an
an existing connection to return for re-use in a full connection
pool, and then it would check if the returned connection was expired.
If the returned connection expired while awaiting re-use, it would
return an error to the location requestiong the new connection.
The existing call sites requesting a new connection was often the last
attempt at returning a connection for a query. This would then
result in a failed query.

This change ensures that we perform the expiry check right
before a connection is inserted back in to the connection pool
for while requesting a new connection. If requesting a new connection
it will no longer fail due to the connection expiring.

Fixes #32530

Change-Id: If16379befe0e14d90160219c0c9396243fe062f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/216197
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
src/database/sql/sql.go
src/database/sql/sql_test.go