fix(tracing): flush log_guard on SIGTERM alongside chrome_guard - #6695
Merged
Conversation
log_guard (the rolling-file WorkerGuard) relied on Drop to flush buffered log writes, the same as chrome_guard before #6692 fixed it. A SIGTERM without a handler skips Drop entirely, discarding whatever lines were still in the async writer's channel (reproduced 6/6 with a tight self-kill race, losing 127-939 lines per run). Generalizes the take-once-cell + SIGTERM-listener pattern from #6692 into an unconditional LogGuardCell, since file logging (unlike Chrome tracing) is not gated behind the profiling feature. Both TracingGuards::drop and spawn_sigterm_flush_task now take-and-flush whichever cell(s) are still Some. Extracts should_install_sigterm_flush_task as a pure, unit-tested gate so a mis-wire of owns_sigterm_elsewhere no longer silently regresses in default builds. Closes #6693
bug-ops
force-pushed
the
fix/6693-log-guard-sigterm-flush-gap
branch
from
July 28, 2026 14:27
a841539 to
699cee8
Compare
bug-ops
enabled auto-merge (squash)
July 28, 2026 14:27
5 tasks
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.
Summary
log_guard(the rolling-fileWorkerGuardinsrc/tracing_init.rs) had the same SIGTERM-flush gapchrome_guardhad before fix(tracing): flush local trace on SIGTERM and fix span-duration fragmentation #6692 fixed it: aSIGTERMwithout a handler skipsDropentirely, discarding whatever log lines were still buffered in the async writer's channel. Reproduced 6/6 with a tight self-kill race, losing 127-939 lines per run; a 50ms-headstart contrast case lost 0/3, explaining why fix(tracing): flush local trace on SIGTERM and fix span-duration fragmentation #6692's informal single-run test didn't repro this.LogGuardCell(file logging isn't gated behind theprofilingfeature, unlike Chrome tracing). BothTracingGuards::dropandspawn_sigterm_flush_tasknow take-and-flush whichever cell(s) are stillSome.owns_sigterm_elsewhereis now unconditional (previouslyprofiling-gated), since the log-guard flush task needs the same "don't race a graceful shutdown path" guard regardless of feature flags. Extracted the gate decision into a pureshould_install_sigterm_flush_task, unit-tested against its full truth table, so a mis-wire no longer silently regresses in default builds.early_ctrlcstill callsprocess::exit(130)and bypasses guard flushing; this is called out as a known, separate limitation (not fixed here).Closes #6693
Test plan
cargo +nightly fmt --checkcargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warningscargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler" --lib --bins(15258 passed)RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace --features "desktop,ide,server,chat,pdf,scheduler"gitleaks protect --stagedtracing_guards_drop_flushes_log_guard_cell,log_guard_cell_take_is_idempotent_under_concurrent_access(genuine OS-thread race),spawn_sigterm_flush_task_does_not_touch_log_guard_before_signal,should_install_sigterm_flush_task_truth_tablepkill -TERMunder active log writes) before the fix, confirming the fix addresses a real, not theoretical, defect