Skip to content

Commit

Permalink
Fix rollback errors in logs (stellar#397)
Browse files Browse the repository at this point in the history
During ingestion we can see the following logs:

WARN[2023-02-06T21:16:22.733+01:00] could not rollback ingest write transactions  error="sql: transaction has already been committed or rolled back" pid=78232

This commit will ignore sql.ErrTxDone errors when rolling back a transaction.
  • Loading branch information
tamirms authored Feb 6, 2023
1 parent 72db26e commit 99114c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/soroban-rpc/internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,14 @@ func (w writeTx) Commit(ledgerSeq uint32) error {
}

func (w writeTx) Rollback() error {
return w.tx.Rollback()
// sql.ErrTxDone is returned when rolling back a transaction which has
// already been committed or rolled back. We can ignore those errors
// because we allow rolling back after commits in defer statements.
if err := w.tx.Rollback(); err == nil || err == sql.ErrTxDone {
return nil
} else {
return err
}
}

func runMigrations(db *sql.DB, dialect string) error {
Expand Down
2 changes: 2 additions & 0 deletions cmd/soroban-rpc/internal/db/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func TestLedgers(t *testing.T) {
assert.NoError(t, err)
assert.NoError(t, tx.LedgerWriter().InsertLedger(createLedger(ledgerSequence)))
assert.NoError(t, tx.Commit(ledgerSequence))
// rolling back after a commit is a no-op
assert.NoError(t, tx.Rollback())
}

assertLedgerRange(t, reader, 1, 10)
Expand Down

0 comments on commit 99114c4

Please sign in to comment.