Skip to content

web: Handle CancelledError from request handlers - #3695

Open
Sanjays2402 wants to merge 1 commit into
tornadoweb:masterfrom
Sanjays2402:fix/request-handler-cancelled-error
Open

web: Handle CancelledError from request handlers#3695
Sanjays2402 wants to merge 1 commit into
tornadoweb:masterfrom
Sanjays2402:fix/request-handler-cancelled-error

Conversation

@Sanjays2402

Copy link
Copy Markdown

asyncio.CancelledError moved outside Exception in Python 3.8, so a cancelled handler bypasses RequestHandler._execute's error path and leaves the client waiting until its timeout. Catch it explicitly so Tornado returns its normal 500 response.

Fixes #2990.

Tested with ErrorResponseTest (including a regression that times out without the source fix), plus flake8, black, and mypy on the changed files. The full 1,244-test run had only the existing macOS test_no_open_redirect failure, reproduced unchanged on the base branch.

asyncio.CancelledError stopped inheriting from Exception in Python 3.8,
so it escaped RequestHandler._execute and left the HTTP request pending.

Catch it alongside ordinary exceptions so the existing error path produces
a response. Add an HTTP regression test for the cancellation path.

Fixes tornadoweb#2990
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.

asyncio task cancellations are orphaned

1 participant