stdlib: close connection on Tx commit or rollback that doesn't end Tx

refs #787
pull/816/head
Jack Christensen 2020-07-13 22:40:42 -05:00
parent 5b498c4529
commit 2583134306
1 changed files with 16 additions and 2 deletions

View File

@ -716,9 +716,23 @@ type wrapTx struct {
tx pgx.Tx
}
func (wtx wrapTx) Commit() error { return wtx.tx.Commit(wtx.ctx) }
func (wtx wrapTx) Commit() error {
pgxConn := wtx.tx.Conn()
err := wtx.tx.Commit(wtx.ctx)
if err != nil && pgxConn.PgConn().TxStatus() != 'I' {
_ = pgxConn.Close(wtx.ctx) // already have error to return
}
return err
}
func (wtx wrapTx) Rollback() error { return wtx.tx.Rollback(wtx.ctx) }
func (wtx wrapTx) Rollback() error {
pgxConn := wtx.tx.Conn()
err := wtx.tx.Rollback(wtx.ctx)
if err != nil && pgxConn.PgConn().TxStatus() != 'I' {
_ = pgxConn.Close(wtx.ctx) // already have error to return
}
return err
}
type fakeTx struct{}