Repository navigation
fix: cancel ASGI application when a waiting request is cancelled - #5772
Open
DiadkoShmek wants to merge 1 commit into
Open
DiadkoShmek wants to merge 1 commit into
DiadkoShmek wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR address?
Cancelling a request before its first ASGI response left
TimeoutMiddleware's separately scheduled application task running. Catch incoming cancellation while awaiting the first-send waiter, cancel and drain the owned task, then re-raise the request cancellation. A cleanup error must not replace that cancellation.The regression uses an actual
@bentoml.service(traffic={"timeout": 60}), its lifespan and an HTTP POST throughhttpx.ASGITransport. It fails on the original middleware because handler cleanup has not completed when cancellation returns. After the change the complete local ASGI test module passes (5 tests); additional lifecycle controls cover cooperative delayed cleanup, cleanup errors, successful responses and the existing prompt 504 path.This handles caller cancellation before response headers. It leaves deadline-triggered and post-header behavior unchanged, and cannot force an application that indefinitely suppresses cancellation to finish. No network-server disconnect or full repository suite is claimed. #5670 addresses a different path: application completion/failure without a first send.
AI assistance: OpenAI Codex investigated, implemented and independently checked this change using local CPU execution. No human code review, provider/model call or upstream acceptance is claimed.
Before submitting:
pre-commit run -ascript has passed?The repository-pinned Ruff lint/format checks pass for both changed files, as does
git diff --check; the complete pre-commit hook set was not run. This internal cancellation repair does not change the public API.