Skip to content

Commit

Permalink
fix: don't call rollback when tx is already done
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Nov 10, 2021
1 parent 421e3de commit 8246c2a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,20 @@ func (db *DB) RunInTx(
if err != nil {
return err
}
defer tx.Rollback() //nolint:errcheck

var done bool

defer func() {
if !done {
_ = tx.Rollback()
}
}()

if err := fn(ctx, tx); err != nil {
return err
}

done = true
return tx.Commit()
}

Expand Down

0 comments on commit 8246c2a

Please sign in to comment.