Repository navigation
gh-162438: Fix premature TimeoutExpired in subprocess.Popen.wait() fallback - #162472
vikash1311994 wants to merge 1 commit into
Conversation
…t() fallback Keep the deadline absolute when the pidfd/kqueue fast path falls back to busy polling.
BHUVANSH855
left a comment
There was a problem hiding this comment.
Sign CLA, so that maintainers can start reviewing.
|
Why will I give you my GitHub access
Regards,
Vikash Khandelwal,
9937710983
…On Mon, Nov 23, 2026, 10:54 PM Bhuvansh ***@***.***> wrote:
***@***.**** commented on this pull request.
Sign CLA, so that maintainers can start reviewing.
—
Reply to this email directly, view it on GitHub
<#162472?email_source=notifications&email_token=ACZDALSVSKXYZR6LORHUTRT52RXDRA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTMMBSGYZDANBUHEY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#pullrequestreview-6026204491>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACZDALSJFN6O4URO262F2DL52RXDRAVCNFSNUABEKJSXA33TNF2G64TZHM4DCNJZHA4TMMJ3JFZXG5LFHM3DKNJRG44DQOBTGGQXMAQ>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/ACZDALU4AKFJCRAU6LJRAKT52RXDRA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTMMBSGYZDANBUHEY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
and Android
<https://github.com/notifications/mobile/android/ACZDALXOEK46DU4CMZX2OM352RXDRA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTMMBSGYZDANBUHEY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
| # polling. | ||
| elapsed = _time() - started | ||
| endtime -= elapsed | ||
| # endtime is an absolute deadline; do not |
There was a problem hiding this comment.
This comment seems to be at the wrong place here, it looks like a continuation of the comment above which isn't the case.
|
Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate. Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors. This contribution appears to have been authored with AI assistance. Please explain your contribution in your own words and describe how you checked its correctness. Please read our guidelines for using AI tools. |
Issue
gh-162438 —
subprocess.Popen.wait(timeout)can raiseTimeoutExpiredearly when the pidfd/kqueue fast path falls back to busy polling.Root cause
Popen._wait()builds an absolute deadline:endtime = started + timeout. In the rare race where the fast wait (_wait_pidfd()/_wait_kqueue()) reports the child gone butwaitpid(WNOHANG)still returns(0, 0), the fallback did:Subtracting already-elapsed time from an absolute deadline moves the deadline earlier. Once more than half of
timeouthad elapsed before the fallback, the busy loop immediately saw a negative remaining time and raisedTimeoutExpired, discarding the child's real exit status. The line was introduced in gh-83069 and is the only such arithmetic in the file.Fix
Remove the subtraction; keep
endtimeabsolute through the fallback so the caller's original deadline is honoured. No platform-specific code, no API change, and no change to the normal (non-race) wait path. There are no other occurrences of this bug shape insubprocess.py.Tests
FastWaitTestCase.test_wait_timeout_not_shortened_in_reap_race: the fast wait reports an exit after 0.25 s of a 0.4 s timeout while the first twoWNOHANGreaps return(0, 0).main):TimeoutExpired— test fails.endtime -= elapsed→ test fails withTimeoutExpired; restored the fix → test passes../python -m test test_subprocess: SUCCESS, 374 tests run, 49 skipped, 0 failures.main: before the fix,TimeoutExpiredafter 2.01 s of a 3 s timeout with child rc 7; after the fix,rc 7is returned.Misc/NEWS.d/next/Libraryentry.Risk
Low: one line removed from a rarely taken fallback branch.
startedis still used to computeendtime. No behavioural change outside the race, no new dependencies.Explicit exclusions
Popen.wait(timeout=float("inf"))raisesTypeError: timeout must be a real number or Noneon macOS/BSD (new kqueue wait path) #154836 is untouched._wait()has a separate implementation and is out of scope.