Repository navigation
Do not write WebSocket handshake response to the tail of the pipeline (#17192) - #17201
Merged
Merged
Conversation
…#17192) `WebSocketServerHandshaker` writes the 101 Switching Protocols response via `Channel.writeAndFlush()`. The write starts at the tail of the pipeline, so every `ChannelOutboundHandler` placed after `WebSocketServerProtocolHandler` sees the raw HTTP upgrade response, even though handlers there operate on WebSocket frames. In #17141 a handler that queues outbound messages until `HandshakeComplete` captured the response itself, so the handshake could never complete. `WebSocketServerHandshaker` already provides `ChannelHandlerContext` overloads for `close()` for the same reason; this change applies the same pattern to the handshake response. - Add `handshake(ChannelHandlerContext, ...)` overloads to `WebSocketServerHandshaker`, following the existing `close(ChannelHandlerContext, ...)` overloads in the same class, and route both variants through a shared `handshake0(ChannelOutboundInvoker, Channel, ...)`. - `WebSocketServerProtocolHandshakeHandler` now passes its ctx, so the response is written from the handshake handler's former position. - Update the benchmarkserver example to use the new overload. - Tests: a regression test asserts a handler behind the protocol handler observes no write during the handshake, for both full and non-full upgrade requests. Existing tests that captured the response behind the protocol handler now read it via `readOutbound()`. Four `handshake(null, ...)` calls needed a `(Channel)` cast to stay unambiguous. Notes: - With the documented pipeline ordering (extension/compression handler before the protocol handler, as in `WebSocketServerInitializer`) nothing changes: the write still traverses `WebSocketServerExtensionHandler` and the HTTP encoder. Only handlers behind the protocol handler stop seeing the 101, which is the bug being fixed. - The tail-write behavior of the `Channel` overloads is unchanged and still covered by `WebSocketServerHandshaker00/08/13Test` and `WebSocketServerHandshakerTest`. Fixes #17141. --------- Co-authored-by: el-psy-kongroo-d <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WebSocketServerHandshakerwrites the 101 Switching Protocols responsevia
Channel.writeAndFlush(). The write starts at the tail of the pipeline,so every
ChannelOutboundHandlerplaced afterWebSocketServerProtocolHandlersees the
raw HTTP upgrade response, even though handlers there operate on
WebSocket
frames. In #17141 a handler that queues outbound messages until
HandshakeCompletecaptured the response itself, so the handshake couldnever
complete.
WebSocketServerHandshakeralready providesChannelHandlerContextoverloads
for
close()for the same reason; this change applies the same patternto the
handshake response.
handshake(ChannelHandlerContext, ...)overloads toWebSocketServerHandshaker, following the existingclose(ChannelHandlerContext, ...)overloads in the same class, androute both
variants through a shared
handshake0(ChannelOutboundInvoker, Channel, ...).WebSocketServerProtocolHandshakeHandlernow passes its ctx, so theresponse
is written from the handshake handler's former position.
observes no write during the handshake, for both full and non-full
upgrade
requests. Existing tests that captured the response behind the protocol
handler now read it via
readOutbound(). Fourhandshake(null, ...)calls
needed a
(Channel)cast to stay unambiguous.Notes:
before
the protocol handler, as in
WebSocketServerInitializer) nothingchanges: the
write still traverses
WebSocketServerExtensionHandlerand the HTTPencoder.
Only handlers behind the protocol handler stop seeing the 101, which is
the
bug being fixed.
Channeloverloads is unchanged andstill
covered by
WebSocketServerHandshaker00/08/13TestandWebSocketServerHandshakerTest.Fixes #17141.
Co-authored-by: el-psy-kongroo-d [email protected]
Co-authored-by: Norman Maurer [email protected]