Skip to content

cache: inflight-coalescing mutex poisoning is silent and sticky #1517

Closed

Description

@thiras

Found by the multi-agent review of #1510. Pre-existing, not introduced there, but the prewarm work made it more consequential so it is worth tracking.

The gap

CacheEngine guards its #305 in-flight fill-coalescing map with a std::sync::Mutex, and both call sites discard a PoisonError:

  • crates/cache/src/engine.rs in get's coalescing loop — self.inner.inflight.lock().ok()
  • crates/cache/src/engine.rs in populate_inner's loop — same
  • InflightGuard::drop — same

On poison, control falls through to a direct pull_through_fill. That fallback is the right behaviour. The problem is that nothing logs it and nothing counts it, and a std::sync::Mutex poison is sticky for the process lifetime.

Why it matters

Coalescing is what stops N concurrent requests for the same missing blob from opening N origin pulls. Once poisoned, the node permanently loses it, with zero log lines and zero metric deltas:

  • On a metered http/s3 origin that is an unbounded multiplier on the egress bill.
  • On populate (local_only = false) the Peer origin is in scope, so it becomes a double-spend of USDC vouchers to upstream nodes — the hazard TeeOpen::InFlight is explicitly documented to prevent ("the caller MUST NOT open a second upstream pull (no double spend)").

The only observable is decdn_cache_pull_through_bytes_total rising faster than request volume — a ratio nobody knows to compute or alert on.

Note the contrast in the same file: a poisoned metrics-only mutex earns a tracing::warn!. The one mutex guarding a financial invariant is the one that is silent.

Suggested fix

Replace the .ok() / if let Ok with an explicit match that, on poison, emits tracing::error! once (latch it behind a Once or AtomicBool so a hot path cannot spam) and bumps a new cache_inflight_mutex_poisoned counter, then falls through to the direct pull exactly as today. The fallback behaviour is correct; only its invisibility is wrong.

The workspace anti-panic policy (unwrap_used/expect_used/panic denied) makes poison close to unreachable, which is the argument for making it loud rather than for tolerating it silently — if it ever fires, it is a genuine bug and the node will otherwise never tell anyone.

Activity

  1. added
    rust
    on Jul 29, 2026
  2. added
    kind:bug
    design:economics
    prio:high
    on Jul 29, 2026
  3. self-assigned this
    on Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

design:economicskind:bugprio:highrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions