diff --git a/tx.go b/tx.go index 944560ef..f19a65a1 100644 --- a/tx.go +++ b/tx.go @@ -157,6 +157,9 @@ func (tx *dbTx) Commit(ctx context.Context) error { commandTag, err := tx.conn.Exec(ctx, "commit") tx.closed = true if err != nil { + if tx.conn.PgConn().TxStatus() != 'I' { + _ = tx.conn.Close(ctx) // already have error to return + } return err } if string(commandTag) == "ROLLBACK" {