Skip to content

node: chain watcher task panics are invisible (detached JoinHandle + zero-valued downtime gauge) #1316

Closed

Description

@yigitdot

Problem

All six LogSink watchers are spawned through resumable_watcher::spawn (crates/node/src/chain_events/resumable_watcher.rs:518-534), which stores the task as _task: AbortOnDrop(...) inside WatcherHandle. AbortOnDrop (crates/node/src/chain_events/mod.rs:75-81) only aborts on drop — it never joins, and the field is never read. The watchers are also not in the runtime JoinSet, so the shutdown-drain log_join_result does not cover them either.

Net effect: a panic in any of the six chain watcher tasks is discarded silently. No log, no counter, no restart.

The sharp edge: the gauge reads zero, not stale

refresh_watcher_down_seconds (crates/node/src/metrics.rs:1661-1712) is computed at scrape time from down_since.elapsed(), where down_since is None on a healthy cycle:

  • Task panics while healthy (down_since == None) -> down_seconds reports 0 forever. A dead watcher is byte-identical to a perfectly healthy one. No threshold alert can fire.
  • Task panics during a backoff window (down_since == Some) -> the gauge keeps climbing and would alert, but only by accident, since nothing else fires.

This corrects the wording in the "Out of scope" section of #1315, which described the gauge as freezing at its last value. In the more likely case that last value is zero, which is strictly worse: it is an unfalsifiable health signal rather than merely a stale one.

Residual coverage gap

Even after #1315 the downtime-recorder family covers 4 of 6 watchers:

  • payment-settlement (crates/node/src/payment_settlement.rs:311) wires no hooks at all.
  • reputation-indexer (crates/node/src/reputation_indexer.rs:126) wires on_backoff only, to a plain reputation_indexer_rpc_failure counter with no down_since / down_seconds pair.

There is also no health or readiness endpoint to aggregate watcher state — /metrics is the only HTTP surface (crates/node/src/metrics.rs:2519-2600) and every other path 404s. The one readiness concept is the startup-only, blacklist-specific oneshot gate.

Why it matters

A dead blacklist loop means the node keeps serving content blacklisted after the failure, which is slashable via SlashJudge.submitBlacklistChallenge.

Honest caveat on severity: a genuine Rust panic is unlikely under the workspace anti-panic clippy policy (unwrap_used / expect_used / panic / indexing_slicing are denied), and ordinary RPC errors are already logged by the poll loop backoff. The defect here is that the health signal cannot distinguish "running fine" from "gone", not that a crash is expected.

Fix options (deliberately not prescribed)

The design decision belongs to whoever picks this up. Three plausible directions:

a. Supervisor inside spawn. Wrap the task so an unexpected exit or panic logs at error! and bumps a metric. One seam, all six watchers benefit.

b. Drop guard. Mirrors the existing in-repo precedent node_pull_through_background_panicked (crates/node/src/metrics.rs:985-995), which solves this exact nothing-awaits-the-handle shape and documents the reasoning — the guard is the only thing that still runs on the unwind. crates/node/src/buyer_channel.rs:441-489 is a second precedent that awaits an inner handle and reports join_err.

c. Liveness / heartbeat gauge. A last-progress timestamp per watcher, so a dead task shows climbing staleness regardless of panic vs wedge. This is the only option that fixes the stuck-at-zero problem directly rather than adding a parallel signal.

Options (a) and (b) make a panic visible; only (c) also covers a task that is alive but wedged in a way the existing hooks do not observe. They are not mutually exclusive.

Closing the two-watcher coverage gap above is in scope for this issue as well, or can be split out if the supervisor work lands first.

Context

Follow-up from the "Out of scope" note in #1315 and the Optional paragraph in #1283. The detached-spawn shape was introduced in #1282.

Activity

  1. added
    kind:feature
    prio:medium
    rust
    on Jul 19, 2026
  2. self-assigned this
    on Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:featureprio:mediumrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions