Skip to content

ledger/snapshot: handle read-only transaction cleanup errors #2278

Description

@wolf31o2

Summary

ledger/snapshot.Calculator discards read-only transaction cleanup errors.

Audit Details

Finding ID: M18, MEDIUM error handling finding.

Affected file: ledger/snapshot/calculator.go.

The audit found:

defer func() { _ = txn.Commit() }()

In this path the transaction is read-only, so commit effectively performs cleanup/rollback. A cleanup error is unlikely, but it is currently invisible.

Impact: database/resource cleanup failures during snapshot calculation are silently lost, making operational issues harder to diagnose.

What Needs to Happen

  1. Replace the discarded cleanup error with an observable path.
  2. If calculation already returned an error, join or log the cleanup error.
  3. If calculation succeeded but cleanup failed, return that error or log at WARN based on transaction semantics.
  4. Add a focused test with a fake transaction if practical.

Acceptance Criteria

  • Cleanup errors are not silently discarded.
  • Successful calculation behavior remains unchanged when cleanup succeeds.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status
Done

Relationships

None yet

Development

No branches or pull requests

Issue actions