system_command: fix potential issue of stderr not being read #16162
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.
This is a blind, possible fix for test flakiness surrounding
stderr
in thesystem_command
tests. I was not able to reproduce the issue locally but did identify a possible cause.The potential bad flow I've identified here:
ProcessTerminatedInterrupt
is received beforeIO.select
signals readable streams (very narrow window that I cannot reproduce - maybe will happen in VMs)readable_sources
is set to all streams andpending_interrupt
is set to truereadable_sources.none?
to loop through and read all streams. Howevernone?
as it was written was guaranteed to short-circuit after the first stream as all possible paths would lead it to returningtrue
(EOF on first stream will return value ofsources.any?
which will be true given we haven't got to the second stream yet).until
loop because ofpending_interrupt
with that second stream not being read yet.The correct behaviour should be to read all
readable_sources
so I've adjusted the logic slightly to make sure that is the case.