Skip to content

Commit

Permalink
Release websocket handshake response if pipeline checks fail (#13338)
Browse files Browse the repository at this point in the history
Motivation:
The WebSocketServerHandshaker require that either an HttpRequestDecoder or an HttpServerCodec exist in the pipeline.
If they do not, we can't send a websocket handshake response.
The handshake response is allocated prior to the pipeline checks.
Therefor, if the checks fail, we need to release the response before returning the failed future.

It might be possible to delay the allocation of the response until after the pipeline checks, but doing so breaks assumptions made by numerous tests.

Modification:
If the pipeline checks fail, release the handshake response before returning the failed promise.

Result:
We no longer leak a buffer in the handshake response if the pipeline checks fail.
  • Loading branch information
chrisvest committed Apr 20, 2023
1 parent 79af2f2 commit f2eca0f
Showing 1 changed file with 1 addition and 0 deletions.
Expand Up @@ -215,6 +215,7 @@ public final ChannelFuture handshake(Channel channel, FullHttpRequest req,
if (ctx == null) {
promise.setFailure(
new IllegalStateException("No HttpDecoder and no HttpServerCodec in the pipeline"));
response.release();
return promise;
}
p.addBefore(ctx.name(), "wsencoder", newWebSocketEncoder());
Expand Down

0 comments on commit f2eca0f

Please sign in to comment.