Skip to content

fix(daemon): bound runtime teardown so a slow zccache exit flush cannot hold the cache-root writer lock - #1991

Merged
zackees merged 2 commits into
mainfrom
agent/daemon-runtime-teardown
Nov 11, 2026
Merged

zackees merged 2 commits into
mainfrom
agent/daemon-runtime-teardown

Conversation

@zackees

@zackees zackees commented Nov 11, 2026

Copy link
Copy Markdown
Member

What

fbuild-daemon can log daemon exiting and then keep running for a minute or
two, still holding zccache's cache-root writer lock. Every replacement daemon on
that root then refuses to start, so the next fbuild build / fbuild deploy
dies with

daemon error: daemon did not become healthy after 3 spawn attempts (10s each)

and a hint about permissions and disk space that never mentions the actual
cause (the live-writer lock).

Root cause: shutdown::persist_and_clean_up bounds the zccache exit flush with
EXIT_FLUSH_BUDGET and logs the timeout, but the flush runs on a
spawn_blocking thread that Tokio cannot cancel. run() then returned, i.e.
dropped the runtime, and Runtime::drop waits for every blocking task — so
the "bounded" flush kept the process (and the lock) alive until the write
finished.

Fix: finish_runtime tears the runtime down with
shutdown_timeout(RUNTIME_TEARDOWN_BUDGET = 250 ms). The abandoned task dies
with the process, exactly as it already does on the SIGTERM path, which calls
process::exit and never drops the runtime.

Closes #1990.

Real-world evidence (Linux, ESP32-C6 on USB-JTAG)

  • Daemon self-evicts 30 s after idle → log: zccache backend flush on exit timed out after 4s then daemon exiting.
  • ps -p <pid> still shows the daemon alive ~60 s later, and /proc/<pid>/fd
    still points at ~/.fbuild/prod/zccache/v1.15.8/.writer.lock (an external
    flock on the same file fails while the corpse lives, succeeds after).
  • Three consecutive daemon spawns were refused:
    WARN zccache::core::cache_root_lock: cache root already has a live writer; refusing to start a second one.
  • Load average ~20; the 30 MB metadata.bin flush does not fit in 4 s there.

Tests

RED → GREEN, one new unit test in shutdown.rs (with the other exit-path
tests; the seam is entry::finish_runtime):

  • Restored to drop(runtime): test ... FAILED — runtime teardown waited 9.903226813s for an abandoned blocking task; it must be bounded by RUNTIME_TEARDOWN_BUDGET (250ms) (test result: FAILED. 0 passed; 1 failed).
  • With the fix: test shutdown::tests::runtime_teardown_does_not_wait_for_an_abandoned_blocking_task ... ok.

Gates (this host):

  • soldr cargo test -p fbuild-daemon --lib → 321 passed; 0 failed; 3 ignored
  • soldr cargo fmt -p fbuild-daemon -- --check → clean (exit 0)
  • soldr cargo clippy -p fbuild-daemon --lib --no-deps -- -A unfulfilled_lint_expectations → exit 0, 0 diagnostics
    (-A unfulfilled_lint_expectations is only needed because pre-existing
    #[expect(cognitive_complexity)] sites misfire on this host)

entry/mod.rs goes 966 → 994 lines, under the 1000-line loc-gate threshold, so
the new test lives beside the other exit-path tests in shutdown.rs instead.

Not done

No attempt to make the flush itself cancellable or faster (that is zccache's
side); this only stops a slow flush from poisoning the next daemon.

…ot hold the cache-root writer lock

`persist_and_clean_up` bounds the zccache exit flush with EXIT_FLUSH_BUDGET
and logs the timeout, but the flush runs on a `spawn_blocking` thread that
Tokio cannot cancel. `run()` then returned, which drops the runtime, and
`Runtime::drop` waits for every blocking task. The process therefore stayed
alive for a minute or two after logging `daemon exiting` while still holding
zccache's cache-root writer lock, so every replacement daemon refused to
start ("cache root already has a live writer") and the next `fbuild build` /
`fbuild deploy` failed with "daemon did not become healthy after 3 spawn
attempts" plus a permissions/disk-space hint that had nothing to do with the
cause.

Bound the teardown with `Runtime::shutdown_timeout(RUNTIME_TEARDOWN_BUDGET)`
behind the `finish_runtime` seam. The SIGTERM path is unaffected: it already
exits the process outright.

Refs #1990
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@zackees
zackees added this pull request to the merge queue Nov 11, 2026
Merged via the queue into main with commit e5f07e0 Nov 11, 2026
30 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 12, 2026
@zackees
zackees deleted the agent/daemon-runtime-teardown branch November 24, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

fix(daemon): bound runtime teardown so a slow zccache exit flush cannot hold the cache-root writer lock

1 participant