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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user