From 9b480f4785d06d39013d32171ab62caacb694002 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Mon, 13 Jul 2020 22:49:35 -0500 Subject: [PATCH] Terminate connection when Commit fails and leaves tx open refs #787 --- tx.go | 3 +++ 1 file changed, 3 insertions(+) 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" {