Repository navigation
Keep the stderr drain thread off rspec doubles in connect specs - #164
Merged
Merged
Conversation
Nine Open3.popen3 stubs handed #connect an instance_double(IO) as stderr. #connect starts a thread that drains stderr, and these examples never close the transport, so the thread outlived them: run during its own example, #each_line was an unexpected message; run during a later one, the double had expired. Both errors are Exceptions, not StandardErrors, so the thread died and Ruby printed the report on $stderr in whichever example was running — which failed main's CI once on Ruby 4.0, inside an `output.to_stderr` matcher of an unrelated example (spec/unit/subprocess_cli_transport_spec.rb:921, run at 07ad108). Ruby 4.0 runs printed the report 26 times in a green run; Ruby 3.x runs printed none. The stubs now return StringIOs for stdout and stderr, as the #read_messages examples in the same file already do, and connect through connect_draining_stderr, which joins the drain (bounded): a double put back fails its own example (21 examples did, with the join and the old doubles) instead of an unrelated later one. spec/README.md gets the convention. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CNgMt2RjeBLyRP3CWFWNy2
Collaborator
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. Another round soon, please! 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.
What and why
CI on
mainfailed once, at 07ad108 (between the merges of #158 and #159), on the Ruby 4.0 leg:The output came from a different example. Nine popen3 stubs (22
#connectcalls over three helpers andsix inline examples in
subprocess_cli_transport_spec.rb, plus the helper inquery_run_end_spec.rb)hand
#connectaninstance_double(IO)as stderr.#connectstarts a thread that drains stderr, and theseexamples never close the transport, so the thread outlives them:
#each_lineis an unexpected message;OutsideOfExampleError, aStandardErrorthat the drainthread's
rescueabsorbs (silently);ExpiredTestDoubleError.Both
MockExpectationErrors areExceptions, notStandardErrors. The thread dies with one and Rubyprints the report on
$stderrin whichever example is running at that moment. When that example isinside an
output.to_stderrmatcher, it fails.The leak predates this batch (the stubs are from 2026-02 to 2026-10-01). It shows up on Ruby 4.0, which CI
has run since #153: the green run at 1e56e56 printed the report 16 times in
test (ubuntu-latest, Ruby 4.0)and 10 times in
deps (latest, Ruby 4.0), and 0 times on Ruby 3.x. Every report names the drain thread(
subprocess_cli_transport.rb:401). The v1.1.0 run onmainprinted none.Change
Specs only.
StringIOs for stdout and stderr, as the#read_messagesexamples in the same filealready do. The drain reads EOF and ends whenever it runs, and no rspec object is involved.
connect_draining_stderr(transport)helper inspec/support/test_helpers.rb:#connect, then a bounded join of the drain thread. If a double comes back, its own example failsdeterministically instead of an unrelated later one (on Ruby 3.4.5: with the join and the old doubles,
the 21 examples behind those 22 calls fail with
received unexpected message :each_line; withStringIOs, 0).spec/README.md: a convention that no background thread may read an rspec double, and the helper.The drain thread's
rescue StandardErrorinlib/stays as it is:MockExpectationError < Exceptionisa test-only fact.
Verification
174 examples, 21 failureson Ruby 3.4.5. Green: withStringIOs,the two spec files pass (174 examples, 0 failures) and no thread reports anything.
gemfiles/latest.gemfileandgemfiles/floor.gemfile;rake rbs:test;RuboCop: 3574 examples, 0 failures on each of the three; 3206, 0 failures under the RBS runtime checker; no offenses.
terminated with exceptionappears 0 times in all 12 job logs,leaked into another example0 times. At 1e56e56 the same two Ruby 4.0 jobs printed it 16 and 10 times.Checklist
bundle exec rakepasses (specs + RuboCop)spec/README.mdlib/changes🤖 Generated with Claude Code
https://claude.ai/code/session_01CNgMt2RjeBLyRP3CWFWNy2