Repository navigation
gh-163101: Reject NaN deadlines in asyncio.timeout - #163113
josh-clairox wants to merge 2 commits into
Conversation
|
📖 2 files modified Preview · build overview · cpython-previews · built Dec. 4, 2026, 6:41 a.m. UTC |
|
One additional regression boundary: rejecting NaN while a timeout is already armed should preserve the old deadline and its cancellation callback. The new reschedule check currently follows reschedule(None), so it only covers an unarmed timeout. A deterministic variant can enter timeout(0), save cm.when() and cm._timeout_handler, call cm.reschedule(float('nan')) under assertRaises(ValueError), assert the deadline/handle are unchanged and the handle is not cancelled, then await asyncio.sleep(0) under an outer assertRaises(TimeoutError). That also proves the original timeout still fires, without a wall-clock delay. I checked this with an AI-assisted original probe on Python 3.12.16/Linux. The installed method accepts NaN and cancels the original handle; substituting only the exact reschedule method from da32179 (blob 64290981f21382423e495e262ca91f1a9daf72a2) into the host Timeout preserves the handle and raises the original TimeoutError on the next yield. This is an isolated method-level check, not a full PR build or upstream-suite result. |
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be put in the comfy chair! |
|
The OP was not even given a chance to submit their own PR and they seem to want to. |
asyncio.timeout(float("nan"))puts a NaN deadline on the loop's timer heap. NaN fails every comparison, so it skips the "already expired" check and breaks the heap's ordering, which delays or cancels unrelated work.This rejects a NaN deadline in
Timeout.reschedule()withValueError, matchingasyncio.sleep().timeout(),timeout_at(),reschedule()andwait_for()all go through that method. Tests, docs and a NEWS entry are included.