Skip to content

fix(tracing): flush log_guard on SIGTERM alongside chrome_guard - #6695

Merged
bug-ops merged 1 commit into
mainfrom
fix/6693-log-guard-sigterm-flush-gap
Jul 28, 2026
Merged

fix(tracing): flush log_guard on SIGTERM alongside chrome_guard#6695
bug-ops merged 1 commit into
mainfrom
fix/6693-log-guard-sigterm-flush-gap

Conversation

@bug-ops

@bug-ops bug-ops commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • log_guard (the rolling-file WorkerGuard in src/tracing_init.rs) had the same SIGTERM-flush gap chrome_guard had before fix(tracing): flush local trace on SIGTERM and fix span-duration fragmentation #6692 fixed it: a SIGTERM without a handler skips Drop entirely, 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.
  • Generalizes fix(tracing): flush local trace on SIGTERM and fix span-duration fragmentation #6692's take-once-cell + SIGTERM-listener pattern into a new, unconditional LogGuardCell (file logging isn't gated behind the profiling feature, unlike Chrome tracing). Both TracingGuards::drop and spawn_sigterm_flush_task now take-and-flush whichever cell(s) are still Some.
  • owns_sigterm_elsewhere is now unconditional (previously profiling-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 pure should_install_sigterm_flush_task, unit-tested against its full truth table, so a mis-wire no longer silently regresses in default builds.
  • CHANGELOG documents this as a behavior change for effectively all builds/invocations (SIGTERM's default disposition is now overridden much more broadly than before), plus a bounded ~1.1s worst-case added SIGTERM-to-exit latency.
  • Corrected a stale doc claim that Ctrl-C behavior was "non-truncating" and unaffected — early_ctrlc still calls process::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 --check
  • cargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warnings
  • cargo 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 --staged
  • New unit tests: tracing_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_table
  • Debugger reproduced the original gap live (pkill -TERM under active log writes) before the fix, confirming the fix addresses a real, not theoretical, defect

@github-actions github-actions Bot added bug Something isn't working size/L Large PR (201-500 lines) documentation Improvements or additions to documentation labels Jul 28, 2026
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
bug-ops force-pushed the fix/6693-log-guard-sigterm-flush-gap branch from a841539 to 699cee8 Compare July 28, 2026 14:27
@bug-ops
bug-ops enabled auto-merge (squash) July 28, 2026 14:27
@bug-ops
bug-ops merged commit 09f616f into main Jul 28, 2026
43 checks passed
@bug-ops
bug-ops deleted the fix/6693-log-guard-sigterm-flush-gap branch July 28, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation size/L Large PR (201-500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

log_guard (rolling file WorkerGuard) has same SIGTERM-flush gap as chrome_guard had

1 participant