fix(logger): bound flush() wait with timeout to prevent caller deadlock (#187)#256
Closed
SAY-5 wants to merge 2 commits intoTrueNine:devfrom
Closed
fix(logger): bound flush() wait with timeout to prevent caller deadlock (#187)#256SAY-5 wants to merge 2 commits intoTrueNine:devfrom
SAY-5 wants to merge 2 commits intoTrueNine:devfrom
Conversation
Fix two CI failures from previous merge
…ck (TrueNine#187) Signed-off-by: SAY-5 <say.apm35@gmail.com>
Owner
|
Merged into dev via cherry-pick. The PR base was changed from main to dev, which caused conflicts because dev had diverged significantly. All commits have been cherry-picked onto dev and pushed. Thanks for the contributions! |
Owner
|
Thank you for the contribution! All commits have been cherry-picked and merged into the dev branch. 🙏 |
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
Fixes #187 —
flush()could block its caller indefinitely if the output worker thread became wedged (deadlocked, sigstop'd, or blocked on a slow stdout pipe). The previousack_rx.recv()was an unbounded wait, so any worker stall would deadlock process shutdown.Change
FLUSH_TIMEOUT = 5sconstant.ack_rx.recv()withack_rx.recv_timeout(FLUSH_TIMEOUT).A healthy worker draining typical bursts of buffered writes finishes well inside the budget. A genuinely wedged worker now loses at most a small tail of output instead of hanging the caller forever — generally the right tradeoff for shutdown paths.
Test plan
cargo build --lib— cleancargo test --lib infra::logger -- --test-threads=1— 16/16 passtest_flush_completes_without_panicstill passestest_thread_safety(which callsflush()after concurrent writers) still passesNote:
test_create_logger_uses_global_levelis flaky under parallelcargo testbecause several logger tests mutate theset_global_levelstatic; unrelated to this change and reproducible onmain.