Skip to content

fix(logger): bound flush() wait with timeout to prevent caller deadlock (#187)#256

Closed
SAY-5 wants to merge 2 commits intoTrueNine:devfrom
SAY-5:fix/issue-187-flush-timeout
Closed

fix(logger): bound flush() wait with timeout to prevent caller deadlock (#187)#256
SAY-5 wants to merge 2 commits intoTrueNine:devfrom
SAY-5:fix/issue-187-flush-timeout

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented Apr 30, 2026

Summary

Fixes #187flush() could block its caller indefinitely if the output worker thread became wedged (deadlocked, sigstop'd, or blocked on a slow stdout pipe). The previous ack_rx.recv() was an unbounded wait, so any worker stall would deadlock process shutdown.

Change

  • Add FLUSH_TIMEOUT = 5s constant.
  • Replace ack_rx.recv() with ack_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 — clean
  • cargo test --lib infra::logger -- --test-threads=1 — 16/16 pass
  • test_flush_completes_without_panic still passes
  • test_thread_safety (which calls flush() after concurrent writers) still passes

Note: test_create_logger_uses_global_level is flaky under parallel cargo test because several logger tests mutate the set_global_level static; unrelated to this change and reproducible on main.

TrueNine and others added 2 commits April 25, 2026 10:10
Fix two CI failures from previous merge
@SAY-5 SAY-5 requested a review from TrueNine as a code owner April 30, 2026 03:29
@TrueNine TrueNine changed the base branch from main to dev April 30, 2026 08:08
@TrueNine
Copy link
Copy Markdown
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!

@TrueNine TrueNine closed this Apr 30, 2026
@TrueNine
Copy link
Copy Markdown
Owner

Thank you for the contribution! All commits have been cherry-picked and merged into the dev branch. 🙏

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.

[Logger/Sink] flush() 可能无限阻塞

2 participants