Skip to content

Commit 334e22f

Browse files
committed
database: Deferred Transaction Rollback
In case of an error before committing the database transaction, the function exits but does not rollback the transaction. By adding a deferred rollback, it will be executed or a no-op if a commit succeeded.
1 parent 296f480 commit 334e22f

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

database/db.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ func (db *DB) NamedBulkExecTx(
574574
if err != nil {
575575
return errors.Wrap(err, "can't start transaction")
576576
}
577+
defer func() { _ = tx.Rollback() }()
577578

578579
stmt, err := tx.PrepareNamedContext(ctx, query)
579580
if err != nil {

0 commit comments

Comments
 (0)