Ensure transactions are cleared when completed

This commit is contained in:
Tobie Morgan Hitchcock 2020-02-17 13:47:09 +00:00
parent e57a088688
commit cbf0ec6f41

View file

@ -257,14 +257,6 @@ func (e *executor) operate(ctx context.Context, stm sql.Statement) (res []interf
loc, trw = true, false loc, trw = true, false
} }
defer func() {
if e.tx != nil {
e.tx.Cancel()
clear(e.id)
e.tx = nil
}
}()
err = e.begin(ctx, trw) err = e.begin(ctx, trw)
if err != nil { if err != nil {
return return
@ -391,6 +383,7 @@ func (e *executor) operate(ctx context.Context, stm sql.Statement) (res []interf
e.tx.Cancel() e.tx.Cancel()
clear(e.id) clear(e.id)
e.tx = nil
default: default:
@ -407,6 +400,7 @@ func (e *executor) operate(ctx context.Context, stm sql.Statement) (res []interf
if err != nil { if err != nil {
e.tx.Cancel() e.tx.Cancel()
clear(e.id) clear(e.id)
e.tx = nil
return return
} }
@ -417,14 +411,18 @@ func (e *executor) operate(ctx context.Context, stm sql.Statement) (res []interf
if !trw { if !trw {
if err = e.tx.Cancel(); err != nil { if err = e.tx.Cancel(); err != nil {
clear(e.id) clear(e.id)
e.tx = nil
} else { } else {
clear(e.id) clear(e.id)
e.tx = nil
} }
} else { } else {
if err = e.tx.Commit(); err != nil { if err = e.tx.Commit(); err != nil {
clear(e.id) clear(e.id)
e.tx = nil
} else { } else {
flush(e.id) flush(e.id)
e.tx = nil
} }
} }