diff --git a/CHANGES/5853.bugfix b/CHANGES/5853.bugfix new file mode 100644 index 00000000000..3b3b03a374f --- /dev/null +++ b/CHANGES/5853.bugfix @@ -0,0 +1 @@ +Don't cancel current task when entering a cancelled timer. diff --git a/aiohttp/helpers.py b/aiohttp/helpers.py index 948b12f99d8..c60397931fb 100644 --- a/aiohttp/helpers.py +++ b/aiohttp/helpers.py @@ -675,7 +675,6 @@ def __enter__(self) -> BaseTimerContext: ) if self._cancelled: - task.cancel() raise asyncio.TimeoutError from None self._tasks.append(task) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 8f029f15666..564ed783848 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -362,7 +362,7 @@ def test_timeout_handle_cb_exc(loop) -> None: assert not handle._callbacks -def test_timer_context_cancelled() -> None: +def test_timer_context_not_cancelled() -> None: with mock.patch("aiohttp.helpers.asyncio") as m_asyncio: m_asyncio.TimeoutError = asyncio.TimeoutError loop = mock.Mock() @@ -373,7 +373,7 @@ def test_timer_context_cancelled() -> None: with ctx: pass - assert m_asyncio.current_task.return_value.cancel.called + assert not m_asyncio.current_task.return_value.cancel.called def test_timer_context_no_task(loop) -> None: