Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't cancel tasks when entering a timer context #5853

Merged
merged 4 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/5853.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't cancel current task when entering a cancelled timer.
1 change: 0 additions & 1 deletion aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,6 @@ def __enter__(self) -> BaseTimerContext:
)

if self._cancelled:
task.cancel()
raise asyncio.TimeoutError from None

self._tasks.append(task)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down