Repository navigation
Worker stderr mirror: read once more after an empty read that raced the stop - #16525
Merged
Merged
Conversation
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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
studio/backend/tests/test_inference_worker_shutdown_exit.py::test_shutdown_exit_still_relays_the_mirrored_stderr_tail(added in #16338) fails intermittently in(Python 3.13, g-r). In the last 30 PRs it hit #16495, #16496, #16498, #16500 and #16509:That is a real product bug, not a flaky test. The worker can drop its last stderr lines when it exits, which are the lines the parent reports when a worker dies.
Cause.
_tail_sink_to_stderr, the mirror pump thread, decided it was done from two separate steps: a read that came back empty, then a check thatstopwas set. If the pump is descheduled between those two steps, the worker writes its last lines to the sink and callsstop_worker_stderr_mirror()in the gap. The pump then sees "empty read, and stop is set", exits, and never relays them.I instrumented the stop sequence in a child that runs the test's exact script, 900 times on 24 threads. On a failing run:
So nothing timed out and nothing was cut off; the lines were simply never read.
Change
studio/backend/utils/worker_stderr.py,_tail_sink_to_stderr: the pump recordsstop.is_set()before each read and only finishes on an empty read that began after the stop was set. Bytes written beforestop.set()are therefore always read. Nothing else changes: the poll interval, compaction, the relay, the join timeouts, and what a live worker mirrors.studio/backend/tests/test_inference_worker_shutdown_exit.py: newtest_the_pump_reads_once_more_after_an_empty_read_that_raced_the_stop. It drives the pump with a reader whose first read returns empty and setsstopin that same call, so the race is forced deterministically rather than left to scheduling.Testing
b'' == b'the last line before shutdown\n')test_shutdown_exit_still_relays_the_mirrored_stderr_tail,--count 40 -n 16--count 80 -n 16, three times)test_inference_worker_shutdown_exit.pyandtest_inference_worker_stderr_tail.py: 77 passed.