Skip to content

Release the handshake response when a WebSocket extension is rejected - #18322

Merged
normanmaurer merged 1 commit into
netty:4.2from
lihanyu1715446406-afk:fix-websocket-extension-response-leak
Nov 10, 2026
Merged

normanmaurer merged 1 commit into
netty:4.2from
lihanyu1715446406-afk:fix-websocket-extension-response-leak

Conversation

@lihanyu1715446406-afk

Copy link
Copy Markdown
Contributor

Motivation:

WebSocketClientExtensionHandler throws CodecException when the server accepts an extension that the client did not offer, but it keeps the FullHttpResponse referenced. The pipeline does not release a message when a handler throws, so the response content buffer leaks. WebSocketServerExtensionHandler already releases the request before throwing in the same situation.

Modification:

Release the response with ReferenceCountUtil before throwing the CodecException.

Result:

The handshake response is released and the leak is gone. Added a regression test that feeds a FullHttpResponse naming an unaccepted extension and asserts the response refCnt drops to 0.

Fixes #18318.

Motivation:
WebSocketClientExtensionHandler throws CodecException when the server
accepts an extension the client did not offer, but it keeps the
FullHttpResponse referenced. The pipeline does not release a message when
a handler throws, so the content buffer leaks.

Modification:
Release the response with ReferenceCountUtil before throwing, matching
WebSocketServerExtensionHandler.

Result:
The response is released and the leak is gone.
@normanmaurer normanmaurer added this to the 4.2.21.Final milestone Nov 10, 2026
@testlens-app

testlens-app Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

🚨 All tests passed but jobs failed 🚨

Failed Jobs without Test Failures

❌ Auto-port to 5.0 / Auto-porting to 5.0

🏷️ Commit: 27dd1f4
▶️ Tests: 128600 executed
⚪️ Checks: 33/33 completed

Rerun Controls

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app/docs.

@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Nov 10, 2026
@normanmaurer
normanmaurer merged commit bc6f58a into netty:4.2 Nov 10, 2026
30 checks passed
@netty-project-bot

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 5.0.

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #18329

@normanmaurer

Copy link
Copy Markdown
Member

Ported to 5.0 in #18330. The cherry-pick had an import conflict, so it needed a manual port.

@normanmaurer normanmaurer removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Nov 10, 2026
normanmaurer added a commit that referenced this pull request Nov 10, 2026
…s rejected (#18322) (#18330)

Motivation:

`WebSocketClientExtensionHandler` throws `CodecException` when the
server accepts an extension that the client did not offer, but it keeps
the `FullHttpResponse` referenced. The pipeline does not release a
message when a handler throws, so the response content buffer leaks.
`WebSocketServerExtensionHandler` already releases the request before
throwing in the same situation.

Modification:

Release the response with `ReferenceCountUtil` before throwing the
`CodecException`.

Result:

The handshake response is released and the leak is gone. Added a
regression test that feeds a `FullHttpResponse` naming an unaccepted
extension and asserts the response `refCnt` drops to 0.

Fixes #18318.

Port notes: resolved an import conflict with CompletionHandler, and the
test declares `throws Exception` because
EmbeddedChannel.finishAndReleaseAll()
throws a checked exception on 5.0.

(cherry picked from commit bc6f58a)

Co-authored-by: LHY_CODE <[email protected]>
normanmaurer added a commit that referenced this pull request Nov 11, 2026
…ion is rejected (#18329)

Auto-port of #18322 to 4.1
Cherry-picked commit: bc6f58a

---
Motivation:

`WebSocketClientExtensionHandler` throws `CodecException` when the
server accepts an extension that the client did not offer, but it keeps
the `FullHttpResponse` referenced. The pipeline does not release a
message when a handler throws, so the response content buffer leaks.
`WebSocketServerExtensionHandler` already releases the request before
throwing in the same situation.

Modification:

Release the response with `ReferenceCountUtil` before throwing the
`CodecException`.

Result:

The handshake response is released and the leak is gone. Added a
regression test that feeds a `FullHttpResponse` naming an unaccepted
extension and asserts the response `refCnt` drops to 0.

Fixes #18318.

---------

Co-authored-by: LHY_CODE <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
Motivation:
The client should not silently accept an unsupported selected extension.
An empty response header, however, does not select an extension and should
not prevent an otherwise ordinary WebSocket connection.

Modification:
Retain the existing nonempty extension selection check. Treat an empty
or HTTP-OWS-only response header as no selection. Add positive handshake
and text-echo tests for both forms, and document the distinction.

Result:
Blank extension response headers allow ordinary WebSocket exchanges.
Nonempty selection handling is unchanged by this follow-up. PJ's separate
request to preserve explicitly offered framing-neutral extensions remains
an unresolved API-policy question; this is not a complete review resolution.

Tests:
- Offline Scala 2.13.18 compilation of changed Handshake.scala and
  WebSocketClientSpec.scala against cached existing module classes: passed.
- Direct ScalaTest WebSocketClientSpec, filtered to "extension response
  value": 2 positive tests passed using those compiled classes and cached
  dependencies. This is not a clean full-project build or Scala 3 result.
- Cached official scalafmt 3.11.5 applied to the two changed Scala files.
- git diff --check: passed.
- Full suite, MiMa, docs/paradox and CI were not run for this revision.

References:
Refs apache#1436 and PJ Fanning review 5938857123.
RFC 6455 section 4.1 item 5.
Original investigation: netty/netty#18322.
pjfanning pushed a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
Motivation:
The client should not silently accept an unsupported selected extension.
An empty response header, however, does not select an extension and should
not prevent an otherwise ordinary WebSocket connection.

Modification:
Retain the existing nonempty extension selection check. Treat an empty
or HTTP-OWS-only response header as no selection. Add positive handshake
and text-echo tests for both forms, and document the distinction.

Result:
Blank extension response headers allow ordinary WebSocket exchanges.
Nonempty selection handling is unchanged by this follow-up. PJ's separate
request to preserve explicitly offered framing-neutral extensions remains
an unresolved API-policy question; this is not a complete review resolution.

Tests:
- Offline Scala 2.13.18 compilation of changed Handshake.scala and
  WebSocketClientSpec.scala against cached existing module classes: passed.
- Direct ScalaTest WebSocketClientSpec, filtered to "extension response
  value": 2 positive tests passed using those compiled classes and cached
  dependencies. This is not a clean full-project build or Scala 3 result.
- Cached official scalafmt 3.11.5 applied to the two changed Scala files.
- git diff --check: passed.
- Full suite, MiMa, docs/paradox and CI were not run for this revision.

References:
Refs apache#1436 and PJ Fanning review 5938857123.
RFC 6455 section 4.1 item 5.
Original investigation: netty/netty#18322.
ikpil added a commit to ikpil/Netty.NET that referenced this pull request Nov 29, 2026
…is rejected (netty/netty#18322)

Motivation:

`WebSocketClientExtensionHandler` throws `CodecException` when the
server accepts an extension that the client did not offer, but it keeps
the `FullHttpResponse` referenced. The pipeline does not release a
message when a handler throws, so the response content buffer leaks.
`WebSocketServerExtensionHandler` already releases the request before
throwing in the same situation.

Modification:

Release the response with `ReferenceCountUtil` before throwing the
`CodecException`.

Result:

The handshake response is released and the leak is gone. Added a
regression test that feeds a `FullHttpResponse` naming an unaccepted
extension and asserts the response `refCnt` drops to 0.

Fixes netty/netty#18318.

Upstream-Commit: netty/netty@bc6f58a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebSocketClientExtensionHandler does not release the handshake response when it rejects an extension

3 participants