Repository navigation
gh-134471: Fix asyncio.timeout(0) swallowing an unrelated prior cancellation. - #134472
okhaliavka wants to merge 1 commit into
Conversation
|
The following commit authors need to sign the Contributor License Agreement: |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
| async def test_timeout_immediately_after_cancellation(self): | ||
| asyncio.current_task().cancel() | ||
| with self.assertRaises(asyncio.CancelledError): | ||
| async with asyncio.timeout(0.0): | ||
| await asyncio.sleep(1) |
There was a problem hiding this comment.
this added test fails on all python versions and the proposed fix makes it pass without breaking any other tests
| self._state = _State.ENTERED | ||
| self._task = task | ||
| self._cancelling = self._task.cancelling() | ||
| self._must_cancel = self._task._must_cancel |
There was a problem hiding this comment.
i feel uneasy messing around with this internal _must_cancel but i didn't find any other way to fix this. changing the cancellation counting logic breaks timeout usage while handling CancelledError, where it should indeed disregard the previous cancellation (the one it's handling). I couldn't get both cases to work by only relying on counting (cancelling).
so i needed something more "surgical" to be able to tell whether we're currently handling CancelledError or we're just in an already cancelled task that didn't get thrown a CancelledError yet
|
This PR is stale because it has been open for 30 days with no activity. |
|
This PR has been blocked on an unsigned CLA for more than 12 months and cannot be merged until all commit authors sign. Closing to cull the number of open pull requests. Do not reopen this pull request without signing the CLA first and getting a go-ahead from a triager or core developer on gh-134471. |
asyncio.timeout(0)swallows a prior task cancellation #134471