Skip to content

fix(top): wake sleeping collectors when sozu top shuts down - #1837

Merged
FlorentinDUBOIS merged 4 commits into
mainfrom
fix/top-shutdown-wakes-collectors
Oct 3, 2026
Merged

FlorentinDUBOIS merged 4 commits into
mainfrom
fix/top-shutdown-wakes-collectors

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Fixes #1829

Cause

CAUSE: bin/src/ctl/top/transport.rs poll_loop waits out interval - elapsed in std::thread::sleep, which nothing can interrupt (certs CERTS_INTERVAL = 30 s, listeners 5 s) -> run_top (bin/src/ctl/top/mod.rs) joins collector, listeners and certs right after render::run returns; dropping their receivers is only observed after the next poll -> SYMPTOM: sozu top exits up to 30 s after its last frame (29.85 s measured after --snapshot 1).

Change

  • run_top creates one crossbeam_channel::bounded::<()>(0) wake channel and hands a receiver clone to each of spawn_collector, spawn_listeners and spawn_certs. This is the idiom the cardinality renewer already uses (renewer_wake_tx in cardinality.rs).
  • poll_loop waits in wake.recv_timeout(interval - elapsed): Timeout -> next poll; Disconnected -> return. Nothing is ever sent on the channel.
  • run_top drops the sender right after setting shutdown and before the joins, so all three threads return at once. The longest wait left is the events thread's EVENTS_READ_TIMEOUT (1 s), plus any round trip already in flight.
  • Docs: transport.rs module docs, the poll_loop contract and the run_top comments describe the wake channel; doc/sozu-top.md states the exit bound; CHANGELOG entry under Unreleased / Fixed.

Regression test

sozu_top_tick_once_against_real_master (bin/tests/sozu_top_e2e.rs, which CI runs on msrv-full with --include-ignored) now pipes the stdout of sozu top --snapshot 1 and measures the gap between the last frame byte and stdout EOF (process exit). Startup and first-frame time on a loaded host are left out. Bound: under 2 s, twice the 1 s events read, as derived in the issue.

  • Red on bd19a78e with the test change alone:
    sozu top took 29.85s to exit after its last frame: shutdown must wake the polling collectors instead of waiting out their interval -> test result: FAILED. 2 passed; 1 failed ... finished in 30.37s
  • Green, three runs with --features tui,opentelemetry,splice,simd on a host at load average ~60 over 20 CPUs: 1.08s, 1.10s, 1.07s -> test result: ok. 3 passed; 0 failed each time. The remaining ~1 s is the events thread's bounded read.

Validation (on e0e6c59)

  • cargo +nightly fmt --check -> exit 0
  • cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings -> exit 0
  • RUSTDOCFLAGS="-D warnings" cargo +1.93.1 doc --no-deps --locked -p sozu-lib -p sozu-command-lib -p sozu -> exit 0
  • cargo +1.93.1 test -p sozu --locked --features tui,opentelemetry,splice,simd --lib -> test result: ok. 147 passed; 0 failed
  • cargo +1.93.1 test -p sozu --locked --features tui,opentelemetry,splice,simd --test sozu_top_e2e -- --include-ignored -> test result: ok. 3 passed; 0 failed (x3)
  • python3 .github/scripts/check_doc_citations.py --root . --base origin/main -> exit 0

After the render loop returned, `run_top` joined the snapshot,
listeners and certs threads, but `poll_loop` waited between polls in
`thread::sleep`, which nothing interrupts. Exit took up to the 30 s
certs cadence: 29.85 s after a `--snapshot 1` frame.

`poll_loop` now waits in `recv_timeout` on a wake channel owned by
`run_top`, which drops the sender before joining, so the three threads
return at once. The longest wait left is the events thread's 1 s
bounded read. The process e2e asserts the gap between the last frame
byte and exit stays under 2 s, twice that read.

Fixes #1829

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit e54f953 into main Oct 3, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sozu top waits up to 30 seconds for sleeping collectors on exit

1 participant