Skip to content

Conversation

lachlan-roberts
Copy link
Contributor

@lachlan-roberts lachlan-roberts commented Sep 5, 2025

Closes #13349
Closes #12235

This change avoids hard closing the websocket connection in cases with a normal close code.

This will avoid a race in HTTP/2 where the RST_STREAM frame is racing against the DATA frame holding the WebSocket close.

See comment #13349 for more details.

else
{
connection.cancelDemand();
connection.getEndPoint().shutdownOutput();
Copy link
Contributor

Choose a reason for hiding this comment

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

Now the EndPoint is not closed here.
We cannot rely on the other peer to behave properly.
How do we close the EndPoint now?

@sbordet sbordet self-requested a review September 17, 2025 09:55
The OnWebSocketClose notification can be called in two cases, if a close frame is received, or if the connection is notified as closed through FrameHandler.onClosed.

The callback should only be succeeded not failed if this is called twice, because this is a normal case.
Received a response close frame and OnWebSocketClose is called through JettyWebSocketFrameHandler.onFrame.
Then the connection is closed so JettyWebSocketFrameHandler.onClosed is called, but we cannot call OnWebSocketClose again.

Signed-off-by: Lachlan Roberts <[email protected]>
@lachlan-roberts
Copy link
Contributor Author

@sbordet please review this PR again.

Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

I'd very much prefer a single state machine. Is there a reason that can't be done?

Comment on lines +41 to +47
enum EndPointState
{
OPEN,
ISHUT,
OSHUT,
CLOSED
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm very VERY cautious about this!

Firstly it is duplicating state from inside the endpoint, which itself knows if it is ISHUT or OSHUT, and you can query that state with endPoint.isInputShutdown() and endpoint.isOutputShutdown(). Duplicating state is never a good idea and always results in at least small period of incoherent state.

But then I do not think that EndPointState is truly an orthogonal state to WebSocketState. Can the endpoint really be in any of those 4 states whilst the session is in any of its states?

@joakime joakime moved this to 👀 In review in Jetty 12.1.3 Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

Failure when closing WebSocket Connection over HTTP/2 Improve WebSocket connection closing

3 participants