Repository navigation
fix(daemon): bound runtime teardown so a slow zccache exit flush cannot hold the cache-root writer lock - #1991
Merged
Merged
Conversation
…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
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
fbuild-daemoncan logdaemon exitingand then keep running for a minute ortwo, still holding zccache's cache-root writer lock. Every replacement daemon on
that root then refuses to start, so the next
fbuild build/fbuild deploydies with
and a hint about permissions and disk space that never mentions the actual
cause (the live-writer lock).
Root cause:
shutdown::persist_and_clean_upbounds the zccache exit flush withEXIT_FLUSH_BUDGETand logs the timeout, but the flush runs on aspawn_blockingthread that Tokio cannot cancel.run()then returned, i.e.dropped the runtime, and
Runtime::dropwaits for every blocking task — sothe "bounded" flush kept the process (and the lock) alive until the write
finished.
Fix:
finish_runtimetears the runtime down withshutdown_timeout(RUNTIME_TEARDOWN_BUDGET = 250 ms). The abandoned task dieswith the process, exactly as it already does on the SIGTERM path, which calls
process::exitand never drops the runtime.Closes #1990.
Real-world evidence (Linux, ESP32-C6 on USB-JTAG)
zccache backend flush on exit timed out after 4sthendaemon exiting.ps -p <pid>still shows the daemon alive ~60 s later, and/proc/<pid>/fdstill points at
~/.fbuild/prod/zccache/v1.15.8/.writer.lock(an externalflockon the same file fails while the corpse lives, succeeds after).WARN zccache::core::cache_root_lock: cache root already has a live writer; refusing to start a second one.metadata.binflush does not fit in 4 s there.Tests
RED → GREEN, one new unit test in
shutdown.rs(with the other exit-pathtests; the seam is
entry::finish_runtime):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).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 ignoredsoldr 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_expectationsis only needed because pre-existing#[expect(cognitive_complexity)]sites misfire on this host)entry/mod.rsgoes 966 → 994 lines, under the 1000-line loc-gate threshold, sothe new test lives beside the other exit-path tests in
shutdown.rsinstead.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.