Repository navigation
fix(top): wake sleeping collectors when sozu top shuts down - #1837
Merged
Merged
Conversation
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]>
Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
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.
Fixes #1829
Cause
CAUSE:
bin/src/ctl/top/transport.rspoll_loopwaits outinterval - elapsedinstd::thread::sleep, which nothing can interrupt (certsCERTS_INTERVAL= 30 s, listeners 5 s) ->run_top(bin/src/ctl/top/mod.rs) joinscollector,listenersandcertsright afterrender::runreturns; dropping their receivers is only observed after the next poll -> SYMPTOM:sozu topexits up to 30 s after its last frame (29.85 s measured after--snapshot 1).Change
run_topcreates onecrossbeam_channel::bounded::<()>(0)wake channel and hands a receiver clone to each ofspawn_collector,spawn_listenersandspawn_certs. This is the idiom the cardinality renewer already uses (renewer_wake_txincardinality.rs).poll_loopwaits inwake.recv_timeout(interval - elapsed):Timeout-> next poll;Disconnected-> return. Nothing is ever sent on the channel.run_topdrops the sender right after settingshutdownand before the joins, so all three threads return at once. The longest wait left is the events thread'sEVENTS_READ_TIMEOUT(1 s), plus any round trip already in flight.transport.rsmodule docs, thepoll_loopcontract and therun_topcomments describe the wake channel;doc/sozu-top.mdstates 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 onmsrv-fullwith--include-ignored) now pipes the stdout ofsozu top --snapshot 1and 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.bd19a78ewith 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--features tui,opentelemetry,splice,simdon a host at load average ~60 over 20 CPUs:1.08s,1.10s,1.07s->test result: ok. 3 passed; 0 failedeach time. The remaining ~1 s is the events thread's bounded read.Validation (on e0e6c59)
cargo +nightly fmt --check-> exit 0cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings-> exit 0RUSTDOCFLAGS="-D warnings" cargo +1.93.1 doc --no-deps --locked -p sozu-lib -p sozu-command-lib -p sozu-> exit 0cargo +1.93.1 test -p sozu --locked --features tui,opentelemetry,splice,simd --lib->test result: ok. 147 passed; 0 failedcargo +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