Skip to content

node: three watchers construct an inert CancellationToken and throw it away — no graceful shutdown path #1230

Closed

Description

@thiras

What

Three watchers pass a CancellationToken they create inline and never retain, so nothing can ever cancel them:

  • slash_watcher.rs — shutdown: CancellationToken::new()
  • reputation_indexer.rs — shutdown: CancellationToken::new()
  • dht/capacity_bond_registry.rs — shutdown: CancellationToken::new()

The only teardown is AbortOnDrop. Compare chain_origin_directory and payment_settlement, which take shutdown as a parameter and are cancelled by the runtime specifically so their cursor flushes.

Why it's currently safe — and why that's fragile

All three use non-persisting cursor policies (HeadMinusWindow), so there is no checkpoint to flush and an abrupt abort loses nothing. The inert token is harmless only because of that coupling, which is invisible at the call site.

The trap: giving any of these a CursorPolicy::Persisted later would silently turn the orphaned token into a checkpoint-flush bug. run only flushes on cfg.shutdown.cancelled(), and that branch is unreachable — so the flush would never run and the failure would be a silently-wider rescan on next boot, not a crash.

Options

  1. Thread the runtime's real token into all three (matches origin/settlement).
  2. Keep AbortOnDrop-only teardown but make the coupling explicit — e.g. have CursorPolicy::Persisted require a live token, so the type system rejects the combination that would break.

(2) is more interesting: it makes the invariant unbreakable instead of documented. Either way, fixing one of the three in isolation is worse than fixing none — the value is in removing the inconsistency.

Follow-up from #1110.

Metadata

Metadata

Assignees

Labels

prio:lowrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions