gh-153962: Re-raise unexpected OSError in subprocess Popen._internal_poll#153964
Open
fedonman wants to merge 3 commits into
Open
gh-153962: Re-raise unexpected OSError in subprocess Popen._internal_poll#153964fedonman wants to merge 3 commits into
OSError in subprocess Popen._internal_poll#153964fedonman wants to merge 3 commits into
Conversation
…ernal_poll On POSIX, Popen._internal_poll() caught every OSError from os.waitpid() and, unless it was ECHILD or the call came from __del__ (a non-None _deadstate), silently discarded it, leaving returncode as None and masking a real failure. Add an else branch that re-raises such unexpected errors. The re-raise is only reachable when _deadstate is None; __del__ and _cleanup() always pass a non-None _deadstate, so __del__ still never raises. ECHILD handling is unchanged.
Contributor
Author
|
@zware part of EuroPython sprint. |
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.
On POSIX,
Popen.poll()caught everyOSErrorfromos.waitpid()but only did something useful with two of them:ECHILD, and the case where the call comes from__del__. Any other error, likeEINVAL, was caught and dropped, which leftreturncodeasNoneand madepoll()look like the child was still running.This adds an
else: raiseso those unexpected errors reach the caller instead of vanishing.The new
raiseonly runs when the call isn't from__del__(that case is handled first, since it passes a deadstate value), so__del__still never raises. TheECHILDbehavior is unchanged.I added a test that patches
subprocess._del_safe.waitpidto raiseEINVALand checks thatpoll()re-raises it. It fails without the change and passes with it, and the rest oftest_subprocessstill passes. The patch goes throughsubprocess._del_safebecause that's the copy ofos.waitpidthis code actually calls.Found as item 8 in devdanzin's standard library audit: https://gist.github.com/devdanzin/3198710e3c0128fda5e0a7b4e0768e5f
Fixes #153962.
Popen._internal_pollsilently swallows unexpectedOSErrorfrom waitpid() #153962