Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serve] Improve handling the websocket server disconnect scenario #42130

Merged
merged 7 commits into from
Jan 7, 2024

Conversation

sihanwang41
Copy link
Contributor

@sihanwang41 sihanwang41 commented Dec 29, 2023

Why are these changes needed?

Server disconnect message is not guaranteed to be sent. So we need to handle it when finish the websocket connection.

Related issue number

Closes: #42124

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: Sihan Wang <sihanwang41@gmail.com>
python/ray/serve/_private/proxy.py Outdated Show resolved Hide resolved
python/ray/serve/_private/proxy.py Outdated Show resolved Hide resolved
python/ray/serve/_private/proxy.py Show resolved Hide resolved
Signed-off-by: Sihan Wang <sihanwang41@gmail.com>
Comment on lines 1043 to 1046
# If the server disconnects, status_code can be set above from the
# disconnect message. but it is not guaranteed.
# If client disconnects, the disconnect code comes from
# a client message via the receive interface, but is is not guaranteed.
Copy link
Contributor

Choose a reason for hiding this comment

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

please fix grammar and punctuation

Copy link
Contributor

@edoakes edoakes left a comment

Choose a reason for hiding this comment

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

Good find.

  • Have you manually confirmed that it fixes the issue in the test?
  • Any automated testing that can/should be added here?

python/ray/serve/_private/proxy.py Outdated Show resolved Hide resolved
Signed-off-by: Sihan Wang <sihanwang41@gmail.com>
Signed-off-by: Sihan Wang <sihanwang41@gmail.com>
Signed-off-by: Sihan Wang <sihanwang41@gmail.com>
Signed-off-by: Sihan Wang <sihanwang41@gmail.com>
@sihanwang41
Copy link
Contributor Author

Good find.

  • Have you manually confirmed that it fixes the issue in the test?
  • Any automated testing that can/should be added here?
  1. Tested locally to make sure there is no traceback in the log.
  2. Add unit test to make sure the last message should always be set. (not None)

Copy link
Contributor

@GeneDer GeneDer left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this case and added test coverage, Sihan!

@@ -547,6 +550,66 @@ async def test_proxy_asgi_receive(self):

queue.close.assert_called_once()

@pytest.mark.asyncio
@pytest.mark.parametrize(
"disconnect",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick (non-blocker): We can probably refactor this to pass a tuple of received messages and expected messages so we don't need to do have the if-else statement below. Just an idea, no strong feeling either way.

@edoakes edoakes merged commit 6724eb8 into ray-project:master Jan 7, 2024
9 checks passed
sihanwang41 added a commit to sihanwang41/ray that referenced this pull request Jan 8, 2024
…y-project#42130)

Server disconnect message is not guaranteed to be sent. So we need to handle it when finish the websocket connection.

---------

Signed-off-by: Sihan Wang <sihanwang41@gmail.com>
architkulkarni pushed a commit that referenced this pull request Jan 8, 2024
…2130) (#42234)

Server disconnect message is not guaranteed to be sent. So we need to handle it when finish the websocket connection.

---------

Signed-off-by: Sihan Wang <sihanwang41@gmail.com>
vickytsang pushed a commit to ROCm/ray that referenced this pull request Jan 12, 2024
…y-project#42130)

Server disconnect message is not guaranteed to be sent. So we need to handle it when finish the websocket connection.

---------

Signed-off-by: Sihan Wang <sihanwang41@gmail.com>
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] NoneType error in test_websockets.py
3 participants