Skip to content

[serve] Prevent ASGI receive() from hanging on disconnects - #44647

Merged
edoakes merged 8 commits into
ray-project:masterfrom
edoakes:better-cancellation
Apr 11, 2024
Merged

edoakes merged 8 commits into
ray-project:masterfrom
edoakes:better-cancellation

Conversation

@edoakes

@edoakes edoakes commented Apr 10, 2024 •

Copy link
Copy Markdown
Collaborator

Why are these changes needed?

See #44644 for the user-reported issue.

In #43713, I changed the behavior of the ASGI receive interface 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 calling receive would be subsequently cancelled anyways. However, this assumption was faulty for a few reasons:

This PR mitigates the issue by returning an appropriate disconnect ASGI 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.

  • Note that this is not a regression from the current behavior and should only happen in practice if the client disconnects very quickly after initiating the request.
  • As a follow-up, we should rework this codepath to something more robust. For example we could use a push-based model where the proxy instead pushes messages eagerly to the replica (this was originally very difficult to implement but should be possible now).

TODO before merging:

  • Manually verify the fix using the reproduction script in the issue.

Related issue number

Closes #44644

Checks

@edoakes
edoakes force-pushed the better-cancellation branch from bda697d to 92ec6c9 Compare April 10, 2024 19:28
@edoakes edoakes changed the title [serve] Fix edge case in DeploymentResponse.cancel() [serve] Prevent ASGI receive() from hanging on disconnects Apr 10, 2024
Signed-off-by: Edward Oakes <[email protected]>
@edoakes
edoakes force-pushed the better-cancellation branch from febc1d6 to a9ade89 Compare April 10, 2024 21:41

@GeneDer GeneDer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread python/ray/serve/_private/http_util.py Resolved
@edoakes
edoakes merged commit 905ca61 into ray-project:master Apr 11, 2024
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.

[Serve] Requests to replicas fail to get cancelled and they get stuck at max ongoing requests

3 participants