Skip to content

Commit 0ebd9da

Browse files
authored
Ignore ErrTxDone when closing transactions (#3738)
Transactions can be closed in indirect ways, such as the context being cancelled. The old code would log an error when then occurred, but the new code checks for the transaction already being closed and treats this as a success. Fixes #3734 and fixes #2998. Note that this doesn't change the behaviour except for the log output spam.
1 parent 1bcf792 commit 0ebd9da

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

storage/mysql/admin_storage.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ func (t *adminTX) Close() error {
132132
return nil
133133
}
134134
t.closed = true
135-
return t.tx.Rollback()
135+
if err := t.tx.Rollback(); err != nil && err != sql.ErrTxDone {
136+
return err
137+
}
138+
return nil
136139
}
137140

138141
func (t *adminTX) GetTree(ctx context.Context, treeID int64) (*trillian.Tree, error) {

storage/mysql/tree_storage.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -413,24 +413,16 @@ func (t *treeTX) Commit(ctx context.Context) error {
413413
return nil
414414
}
415415

416-
func (t *treeTX) rollbackInternal() error {
417-
t.closed = true
418-
if err := t.tx.Rollback(); err != nil {
419-
klog.Warningf("TX rollback error: %s, stack:\n%s", err, string(debug.Stack()))
420-
return err
421-
}
422-
return nil
423-
}
424-
425416
func (t *treeTX) Close() error {
426417
t.mu.Lock()
427418
defer t.mu.Unlock()
428419
if t.closed {
429420
return nil
430421
}
431-
err := t.rollbackInternal()
432-
if err != nil {
422+
t.closed = true
423+
if err := t.tx.Rollback(); err != nil && err != sql.ErrTxDone {
433424
klog.Warningf("Rollback error on Close(): %v", err)
425+
return err
434426
}
435-
return err
427+
return nil
436428
}

0 commit comments

Comments
 (0)