Skip to content

fix(node): forget_loss/record_loss resurrection race leaves a permanent floor-loss row #1781

Closed

Description

@thiras

Found while reviewing #1780, which made PoolFloorLossStore monotonic. The race predates that PR; what the PR changes is that it is no longer self-healing.

The interleaving

forget_pool_floor (crates/node/src/handlers/client/mod.rs:1616-1637) drops the in-memory entry, then dispatches the durable delete:

{ guard.remove(&pool_id); }                                  // in-memory
tokio::task::spawn_blocking(move || store.forget_loss(pool_id)).await;

FloorReservation::drop (mod.rs:455-500) reads its cumulative total under the same lock and then dispatches its own write:

let snapshot = { /* under self.map.lock() */ entry.dead_charge };
// ...
handle.spawn_blocking(move || store.record_loss(pool_id, micro));

The early return at mod.rs:465 (guard.get_mut(&self.pool_id) → None → skip) closes most of the window. It does not close the case where a guard already took its snapshot under the lock and has not yet run its spawn_blocking. That record_loss can land after forget_loss commits, re-inserting the row.

Why it is now permanent

Before #1780 the store overwrote, so any later record_loss could correct the row downward. Now forget_loss is the only downward transition and it has already fired for this pool — no second one is coming, because the pool is closed. The resurrected row survives every subsequent boot.

Runtime::new hydrates unconditionally from load_losses() (mod.rs:1109-1125) and deliberately fails closed on error, so each leaked row becomes a permanent PoolFloorState entry for a pool that no longer exists.

Impact

Not mis-accounting: the doc at mod.rs:1614-1615 is right that a reclaimed pool_id never recurs (monotonic open nonce), so the stale dead_charge is never consulted for a real pool. It is unbounded state growth — one row per closed pool that hits the race, accumulating in lanes.redb and in the boot-time HashMap for the life of the node, with nothing that reclaims it.

Options

  1. Have record_loss skip a pool that is absent from the live floor map (needs the map reachable from the store call site, or the check hoisted into the caller before dispatch).
  2. Have forget_loss write a tombstone that a late record_loss respects, swept at boot.
  3. Await in-flight persists for a pool before forget_loss — cleanest semantically, but needs per-pool tracking of dispatched spawn_blocking work.

No test covers the interleaving today; whichever route is taken should add one.

Activity

  1. added
    kind:bug
    prio:medium
    rust
    on Aug 24, 2026
  2. moved this from Backlog to In progress in deCDNon Aug 24, 2026
  3. moved this from In progress to Done in deCDNon Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugprio:mediumrust

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions