Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Is OnWebSocketClose called after OnWebSocketError?

Hi James,

The `OnWebSocketClose` will always be called for a WebSocket connection.
However there are two reasons could be called and this determines whether `OnWebSocketError` is called before or after `OnWebSocketClose`.

1. You have just received a CLOSE frame and may now send a close response (this will be done automatically by the implementation if you do not do it). In this case `session.isOpen()` will return true. `OnWebSocketError` may be called after this if there is an error sending the CLOSE response frame.

2. The connection has been closed, if there was an error then `onError` will have been called directly before this.

So you should have your cleanup code in `OnWebSocketClose`, because it will always be called. 
But note that in case 1 the connection is still output open during the `OnWebSocketClose` event.

On Tue, Sep 12, 2023 at 12:23 AM James Reeves via jetty-users <jetty-users@xxxxxxxxxxx> wrote:
Hi,

I'm using the Jetty WebSocket API (for Jetty 11, if that makes a difference). I'm looking at the documentation for the OnWebSocketError event, and it says that this will close the session. However, I'm unable to find out whether this will in turn trigger the OnWebSocketClose event.

Essentially I want to know if I can put cleanup code under the OnWebSocketClose event, or if I have to also put it under OnWebSocketError to guarantee it executes if the websocket closes due to an error.

--
James Reeves


_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top