From 8246c2a63e2e6eba314201c6ba87f094edf098b9 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Wed, 10 Nov 2021 09:14:54 +0200 Subject: [PATCH] fix: don't call rollback when tx is already done --- db.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/db.go b/db.go index 2d7a20f90..d42669493 100644 --- a/db.go +++ b/db.go @@ -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() }