Repository navigation
[serve] Prevent ASGI receive() from hanging on disconnects - #44647
Merged
Merged
Conversation
edoakes
force-pushed
the
better-cancellation
branch
from
April 10, 2024 19:28
bda697d to
92ec6c9
Compare
DeploymentResponse.cancel()receive() from hanging on disconnects
Signed-off-by: Edward Oakes <[email protected]>
edoakes
force-pushed
the
better-cancellation
branch
from
April 10, 2024 21:41
febc1d6 to
a9ade89
Compare
Signed-off-by: Edward Oakes <[email protected]>
GeneDer
approved these changes
Apr 10, 2024
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
shrekris-anyscale
approved these changes
Apr 10, 2024
Signed-off-by: Edward Oakes <[email protected]>
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.
Why are these changes needed?
See #44644 for the user-reported issue.
In #43713, I changed the behavior of the ASGI
receiveinterface to not raise an exception but rather silently hang if the request was not present in the proxy. This was done under the assumption that the code callingreceivewould be subsequently cancelled anyways. However, this assumption was faulty for a few reasons:CancelledErrorbut still want to fetchASGImessages.run_coroutine_threadsafe/concurrent.futures.Executorinterface, there is no way to guarantee that either the scheduling task is cancelled or the resulting object ref is cancelled. In rare cases, neither may happen (see asyncio.run_coroutine_threadsafe leaves underlying cancelled asyncio task running python/cpython#105836).This PR mitigates the issue by returning an appropriate
disconnectASGI message when the proxy no longer has the request in scope.Note that this is not a perfect solution: we may still drop the messages prior to the disconnect (e.g., the body of the HTTP request) if the replica does not fetch them prior to the client disconnecting.
TODO before merging:
Related issue number
Closes #44644
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.