Skip to content

Let caller cancellation propagate from ApplicationCommunicator.wait() - #613

Open
BlueX888 wants to merge 1 commit into
django:mainfrom
BlueX888:contrib/wait-cancellation
Open

BlueX888 wants to merge 1 commit into
django:mainfrom
BlueX888:contrib/wait-cancellation

Conversation

@BlueX888

@BlueX888 BlueX888 commented Nov 7, 2026 •

Copy link
Copy Markdown

What do these changes do?

ApplicationCommunicator.wait() caught every asyncio.CancelledError and returned None, so an outer asyncio.wait_for() or asyncio.timeout() around it timed out silently, and an external Task.cancel() was swallowed.

Re-raise when the calling task is cancelling, keep swallowing the application task's own cancellation, and keep wait(timeout=...)'s own timeout silent by checking Timeout.expired(). The cleanup await in the finally block gets the same guard, and an application-raised TimeoutError is not mistaken for the method's own timeout.

Are there changes in behavior for the user?

Yes, but only for cancellation initiated by the caller: an outer timeout now raises TimeoutError and external cancellation raises CancelledError. An application that cancels itself still makes wait() return None, and wait(timeout=...) still returns None after cancelling the application.

Is it a substantial burden for the maintainers to support this?

No. It is a local change in asgiref/testing.py plus regression tests, with no API change.

Related issue number

No linked issue; this report includes a reproducer. I can open one if the project requires a ticket.

Agent run details (optional, for reviewers)
  • Base: 03dcd190a363be6e501b2819803e70495200551c.
  • pytest -q: 129 passed, 1 skipped, 1 xfailed.
  • New tests cover outer wait_for and asyncio.timeout, external Task.cancel(), application self-cancellation, wait(timeout=...), application-raised TimeoutError, and cleanup when an invalid timeout value raises TypeError.
  • Reverting only the source change makes the three caller-cancellation tests fail; application self-cancellation and the method's own timeout still pass.
  • pre-commit (black, isort, flake8, pyupgrade, yesqa) and mypy . pass.

Prepared with Claude Code, an LLM agent operating the BlueX888 account.

@BlueX888
BlueX888 force-pushed the contrib/wait-cancellation branch from 10ea3d1 to 7029660 Compare November 7, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant