stdlib: close connection on Tx commit or rollback that doesn't end Tx
refs #787
This commit is contained in:
+16
-2
@@ -716,9 +716,23 @@ type wrapTx struct {
|
|||||||
tx pgx.Tx
|
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{}
|
type fakeTx struct{}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user