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

Graceful stop of WebSocketClient does not notify server #10918

Closed
chylek-qr opened this issue Nov 24, 2023 · 2 comments
Closed

Graceful stop of WebSocketClient does not notify server #10918

chylek-qr opened this issue Nov 24, 2023 · 2 comments
Labels

Comments

@chylek-qr
Copy link

Jetty Version
11.0.18

Java Version
17

Question
Hi, I'm not sure I understand how the graceful stop (PR #4931) is supposed to work - if I call WebSocketClient#stop, it ends up calling SessionTracker#doStop which according to the PR clears the sessions without notifying the server via close(StatusCode.NORMAL). Setting WebSocketClient#setStopAtShutdown(true) and shutting down the program also doesn't notify the server.

#4919 states this intended order of stop operations:

  1. Stop accepting new websocket connections.
  2. Stop the SessionTracker which will close any existing connections.
  3. Shut down everything else.

Is step 2 not supposed to close connections and wait for the write, at least until the shutdown timeout? It seems to me that stopping the SessionTracker ends up ignoring existing sessions instead of closing them.

I suppose that before calling stop, I can close the sessions manually while also blocking new connections to prevent a race condition, but The Programming Guide's paragraph on stopping the WebSocket client for Jetty 10-12 doesn't mention this.

Thanks!

@lachlan-roberts
Copy link
Contributor

lachlan-roberts commented Nov 24, 2023

The SesssionTracker implements the Graceful interface. This has a method CompletableFuture<Void> shutdown() which iterates over the sessions closing them with a websocket close status code of 1001 which indicates the endpoint is being shutdown.

The WebSocketClient.doStop() calls Graceful.shutdown(this).get(getStopTimeout(), TimeUnit.MILLISECONDS) which should attempt graceful shutdown of the SessionTracker.

Is the graceful shutdown of the WebSocketClient not working for you? or are you just trying to determine how it is working?

@chylek-qr
Copy link
Author

Strange, it was not working for me a few days ago - I was hitting a breakpoint on SessionTracker#doStop, was not hitting a breakpoint on the session.close call in SessionTracker#shutdown, and onWebSocketClose on the server side was not being called. I tried it again now and the shutdown works as expected.

The only thing I can think of is that the thread got interrupted somehow which would skip the session.close call. I can't remember if I tried to place the breakpoint at the beginning of the loop or not... oh well. I assume it was an error on my end then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants