From cbf0ec6f416cf5dcc1378fddfa272cda7a922a19 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 17 Feb 2020 13:47:09 +0000 Subject: [PATCH] Ensure transactions are cleared when completed --- db/executor.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/db/executor.go b/db/executor.go index c0491543..a8ec61c9 100644 --- a/db/executor.go +++ b/db/executor.go @@ -257,14 +257,6 @@ func (e *executor) operate(ctx context.Context, stm sql.Statement) (res []interf loc, trw = true, false } - defer func() { - if e.tx != nil { - e.tx.Cancel() - clear(e.id) - e.tx = nil - } - }() - err = e.begin(ctx, trw) if err != nil { return @@ -391,6 +383,7 @@ func (e *executor) operate(ctx context.Context, stm sql.Statement) (res []interf e.tx.Cancel() clear(e.id) + e.tx = nil default: @@ -407,6 +400,7 @@ func (e *executor) operate(ctx context.Context, stm sql.Statement) (res []interf if err != nil { e.tx.Cancel() clear(e.id) + e.tx = nil return } @@ -417,14 +411,18 @@ func (e *executor) operate(ctx context.Context, stm sql.Statement) (res []interf if !trw { if err = e.tx.Cancel(); err != nil { clear(e.id) + e.tx = nil } else { clear(e.id) + e.tx = nil } } else { if err = e.tx.Commit(); err != nil { clear(e.id) + e.tx = nil } else { flush(e.id) + e.tx = nil } }