Repository navigation
Fix intermittent failure of test/leaky-handles.py - #4932
Merged
Merged
Conversation
The test counted the entries in /proc/<shell pid>/fd using a shell pipeline. $$ is the shell, not ls, and for a pipeline the shell creates a pipe, forks both commands, and only then closes its own copies of the pipe ends. When ls reached getdents() first it saw those too and printed 4 or 5 instead of 3, failing the exact stdout match. Measured at roughly 0.5% when the shell and ls contend for a cpu (2 failures in 400 runs of the test pinned to one cpu), which is why it showed up under parallel and loaded test runs but never in isolation. The forked command now reports the inherited handles itself, so no shell pipe is involved: 0 failures in 400 runs under the same conditions. This also restores what the test is meant to check. The handle it leaked could not reach the child for two unrelated reasons: the 'with' block closed it when the SConstruct finished being read, well before the build phase forked the command, and handles are close-on-exec by default since Python 3.4 (PEP 446) regardless of what SCons does. Binding the file object to an SConscript global is not enough either, as it is garbage collected before the build phase; the test now keeps an os-level handle open and marks it inheritable. Verified it fails as intended when close_fds is removed from SCons/Platform/posix.py. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
The test counted the entries in /proc//fd using a shell pipeline. $$ is the shell, not ls, and for a pipeline the shell creates a pipe, forks both commands, and only then closes its own copies of the pipe ends. When ls reached getdents() first it saw those too and printed 4 or 5 instead of 3, failing the exact stdout match. Measured at roughly 0.5% when the shell and ls contend for a cpu (2 failures in 400 runs of the test pinned to one cpu), which is why it showed up under parallel and loaded test runs but never in isolation.
The forked command now reports the inherited handles itself, so no shell pipe is involved: 0 failures in 400 runs under the same conditions.
This also restores what the test is meant to check. The handle it leaked could not reach the child for two unrelated reasons: the 'with' block closed it when the SConstruct finished being read, well before the build phase forked the command, and handles are close-on-exec by default since Python 3.4 (PEP 446) regardless of what SCons does. Binding the file object to an SConscript global is not enough either, as it is garbage collected before the build phase; the test now keeps an os-level handle open and marks it inheritable. Verified it fails as intended when close_fds is removed from SCons/Platform/posix.py.
Contributor Checklist:
CHANGES.txtandRELEASE.txt(and read theREADME.rst).