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
}
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
}
}