2
0

stdlib.ReleaseConn closes connections left in invalid state

If a connection is in a transaction or has an open result set then
close the connection when returning it to database/sql. When next
database/sql attempts to use it the connection will return
driver.ErrBadConn and database/sql will remove it from the pool.

fixes #673
This commit is contained in:
Jack Christensen
2020-02-01 12:00:26 -06:00
parent 06c3181836
commit 77c1076d39
2 changed files with 39 additions and 0 deletions
+6
View File
@@ -570,6 +570,12 @@ func ReleaseConn(db *sql.DB, conn *pgx.Conn) error {
var tx *sql.Tx
var ok bool
if conn.PgConn().IsBusy() || conn.PgConn().TxStatus() != 'I' {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
conn.Close(ctx)
}
fakeTxMutex.Lock()
tx, ok = fakeTxConns[conn]
if ok {