Repository navigation
Orchestrator shutdown tests: write the partial frame directly instead of racing the drainer - #17782
Conversation
… of racing the drainer test_worker_crash_mid_frame_cannot_block_the_shutdown_deadline failed three times today on unrelated PRs (#17645, #17743, #17776) with the runner exiting 1. Its worker put a 1 MiB frame and then polled its own end of the reply pipe before crashing, but the shutdown path under test starts a drainer thread that reads that same pipe. When the drainer took the whole frame first, the poll waited its full 30 s and the parent's 30 s join expired first. test_forced_shutdown_does_not_read_an_interrupted_queue_frame polls the same pipe the same way. Write a length header plus 32 KiB of the frame straight to the pipe instead, so the reader is left inside a partial frame deterministically, and signal the interrupted-writer test with an event rather than a poll.
|
@codex review |
Codex Review Summary: ✅ CompletedThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d17f4bfd30
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
Without it the worker could exit before the feeder thread wrote any of the frame, so the crash test would pass on an empty pipe instead of an interrupted frame.
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
Problem
studio/backend/tests/test_orchestrator_switch_waits.py::test_worker_crash_mid_frame_cannot_block_the_shutdown_deadlinefailed three times today on PRs that do not touch the orchestrator (#17645, #17743 and #17776), all with the same signature:The worker in that test does
replies.put(<1 MiB frame>)and thenassert replies._reader.poll(30)on its own end of the reply pipe before crashing. But the code under test,_shutdown_subprocess->_drain_unread_replies, starts a drainer thread that reads that same pipe. When the drainer gets the whole frame first, the worker's poll finds nothing and waits its full 30 s, while the parent'sproc.join(30)expires first and seesexitcode is None.test_forced_shutdown_does_not_read_an_interrupted_queue_framepolls the same pipe from the parent and has the same race.The orchestrator is fine. The tests depended on thread scheduling.
Fix
A helper,
_write_partial_frame, writes a length header claiming the whole 1 MiB frame plus the first 32 KiB of it straight to the pipe, then the worker crashes (or sleeps, for the interrupted-writer test). This is less than one pipe buffer, so the write never blocks. Any reader is left inside a partial frame every time, which is the state both tests mean to set up. The interrupted-writer test now waits on awroteevent instead of polling the shared pipe. On Windows, wherePipeConnectionhas no raw write, the helper falls back to the oldput.Tests
time.sleep(1)in the worker before its poll:assert 1 == 0, the same error as CI. With the same delays added around the new partial write, both tests still pass.test_orchestrator_switch_waits.py: 14 passed, three times under-n 8.