Skip to content

HTTP/2: Release compressors after failed headers writes - #17253

Merged
normanmaurer merged 2 commits into
netty:4.2from
Gimini-3:fix-http2-compressor-cleanup
Aug 11, 2026
Merged

normanmaurer merged 2 commits into
netty:4.2from
Gimini-3:fix-http2-compressor-cleanup

Conversation

@Gimini-3

Copy link
Copy Markdown
Contributor

Motivation

CompressorHttp2ConnectionEncoder creates an EmbeddedChannel before delegating a HEADERS write. A delegate may fail the promise without throwing and without creating a stream, for example when a client writes headers with an invalid even stream ID. In that case, the compressor is never attached to a stream and is not released by onStreamRemoved.

A compressor can also be left open if the delegate throws after compressor creation, or if target content encoding preparation fails.

Modification

  • Keep ownership of newly created compressors until they are attached to a stream.
  • Release compressors that are not attached after either writeHeaders overload returns or throws.
  • Release partially initialized compressors if header preparation fails.
  • Add regression tests for both overloads covering missing streams, synchronous and asynchronous failures, and existing streams in invalid states.

Result

Failed HEADERS writes no longer leave compression EmbeddedChannels open, while compressors attached to streams continue to be released by the existing stream-removal path.

Testing

  • ./mvnw -pl codec-http2 -Dtest=CompressorHttp2ConnectionEncoderTest test
  • ./mvnw -pl codec-http2 -Dtest=CompressorHttp2ConnectionEncoderTest,DataCompressionHttp2Test test
  • ./mvnw -pl codec-http2 test

@Gimini-3
Gimini-3 marked this pull request as ready for review August 10, 2026 18:18

@normanmaurer normanmaurer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

one comment otherwise LGTM

} else {
headers.set(CONTENT_ENCODING, targetContentEncoding);
}
boolean success = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

consider using the same patterns as before (setting compressor to null and only release in finally block when not null)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to use a null compressor as the ownership marker and only release it from the finally block. Thanks.

@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 Aug 11, 2026
@normanmaurer normanmaurer added this to the 4.2.18.Final milestone Aug 11, 2026

@normanmaurer normanmaurer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great catch!

@testlens-app

testlens-app Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

🚨 TestLens detected 1 failed test 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Test Summary

Build PR / linux-x86_64-java11-boringssl build > Netty/Codec/HTTP2

Test Runs Flakiness
DataCompressionHttp2Test > encodingTooBigMessage(int, AsciiString) > [8] 10, snappy ❌ ✅ 1% 🟡

Build PR / macos-aarch64-java11-boringssl build > Netty/Transport/Native/KQueue

Test Runs Flakiness
KQueueCompositeBufferGatheringWriteTest > testCompositeBufferPartialWriteDoesNotCorruptData(TestInfo) ❌ ✅ 1% 🟡
KQueueCompositeBufferGatheringWriteTest > testSingleCompositeBufferWrite(TestInfo) ❌ ✅ 1% 🟡

Build PR / macos-x86_64-java11-boringssl build > Netty/Transport/Native/KQueue

Test Runs Flakiness
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeDirectByteBuf(TestInfo) ❌ ✅ 5% 🟠
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendHeapByteBuf(TestInfo) ✅ ❌ 3% 🟡

🏷️ Commit: 1c16c9b
▶️ Tests: 39149 executed
⚪️ Checks: 18/18 completed

Test Failures

KQueueDatagramUnicastIPv6MappedTest > testSimpleSendHeapByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-x86_64-java11-boringssl build)
org.opentest4j.AssertionFailedError
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend0(DatagramUnicastTest.java:360)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend(DatagramUnicastTest.java:192)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendHeapByteBuf(DatagramUnicastTest.java:103)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$2.run(DatagramUnicastTest.java:97)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$2.run(DatagramUnicastTest.java:94)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendHeapByteBuf(DatagramUnicastTest.java:94)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

Muted Tests

Select tests to mute in this pull request:

  • DataCompressionHttp2Test > encodingTooBigMessage(int, AsciiString)
  • KQueueCompositeBufferGatheringWriteTest > testCompositeBufferPartialWriteDoesNotCorruptData(TestInfo)
  • KQueueCompositeBufferGatheringWriteTest > testSingleCompositeBufferWrite(TestInfo)
  • KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeDirectByteBuf(TestInfo)
  • KQueueDatagramUnicastIPv6MappedTest > testSimpleSendHeapByteBuf(TestInfo)

Reuse successful test results:

  • ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app.

@Gimini-3

Copy link
Copy Markdown
Contributor Author

Could someone with the required permissions please re-run the failed jobs? The macOS failures are in unrelated kqueue tests, and the Linux BoringSSL failure is a timeout in DataCompressionHttp2Test. The related tests pass locally and also passed in the previous CI run. Thanks.

@normanmaurer
normanmaurer merged commit c797c2f into netty:4.2 Aug 11, 2026
31 of 35 checks passed
@normanmaurer

Copy link
Copy Markdown
Member

@Gimini-3 thanks a lot!

@netty-project-bot

Copy link
Copy Markdown
Contributor

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

@normanmaurer

Copy link
Copy Markdown
Member

Port for 5.0: #17264

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #17265

@github-actions github-actions Bot removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Aug 11, 2026
normanmaurer pushed a commit that referenced this pull request Aug 12, 2026
#17265)

Auto-port of #17253 to 4.1
Cherry-picked commit: c797c2f

---
### Motivation

`CompressorHttp2ConnectionEncoder` creates an `EmbeddedChannel` before
delegating a HEADERS write. A delegate may fail the promise without
throwing and without creating a stream, for example when a client writes
headers with an invalid even stream ID. In that case, the compressor is
never attached to a stream and is not released by `onStreamRemoved`.

A compressor can also be left open if the delegate throws after
compressor creation, or if target content encoding preparation fails.

### Modification

- Keep ownership of newly created compressors until they are attached to
a stream.
- Release compressors that are not attached after either `writeHeaders`
overload returns or throws.
- Release partially initialized compressors if header preparation fails.
- Add regression tests for both overloads covering missing streams,
synchronous and asynchronous failures, and existing streams in invalid
states.

### Result

Failed HEADERS writes no longer leave compression `EmbeddedChannel`s
open, while compressors attached to streams continue to be released by
the existing stream-removal path.

### Testing

- `./mvnw -pl codec-http2 -Dtest=CompressorHttp2ConnectionEncoderTest
test`
- `./mvnw -pl codec-http2
-Dtest=CompressorHttp2ConnectionEncoderTest,DataCompressionHttp2Test
test`
- `./mvnw -pl codec-http2 test`

Co-authored-by: Gimin Kim <[email protected]>
normanmaurer added a commit that referenced this pull request Aug 12, 2026
)

`CompressorHttp2ConnectionEncoder` creates an `EmbeddedChannel` before
delegating a HEADERS write. A delegate may fail the promise without
throwing and without creating a stream, for example when a client writes
headers with an invalid even stream ID. In that case, the compressor is
never attached to a stream and is not released by `onStreamRemoved`.

A compressor can also be left open if the delegate throws after
compressor creation, or if target content encoding preparation fails.

- Keep ownership of newly created compressors until they are attached to
a stream.
- Release compressors that are not attached after either `writeHeaders`
overload returns or throws.
- Release partially initialized compressors if header preparation fails.
- Add regression tests for both overloads covering missing streams,
synchronous and asynchronous failures, and existing streams in invalid
states.

Failed HEADERS writes no longer leave compression `EmbeddedChannel`s
open, while compressors attached to streams continue to be released by
the existing stream-removal path.

- `./mvnw -pl codec-http2 -Dtest=CompressorHttp2ConnectionEncoderTest
test`
- `./mvnw -pl codec-http2
-Dtest=CompressorHttp2ConnectionEncoderTest,DataCompressionHttp2Test
test`
- `./mvnw -pl codec-http2 test`

Co-authored-by: Gimin Kim <[email protected]>
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
@normanmaurer normanmaurer removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Oct 16, 2026
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
netty#17265)

Auto-port of netty#17253 to 4.1
Cherry-picked commit: c797c2f

---
### Motivation

`CompressorHttp2ConnectionEncoder` creates an `EmbeddedChannel` before
delegating a HEADERS write. A delegate may fail the promise without
throwing and without creating a stream, for example when a client writes
headers with an invalid even stream ID. In that case, the compressor is
never attached to a stream and is not released by `onStreamRemoved`.

A compressor can also be left open if the delegate throws after
compressor creation, or if target content encoding preparation fails.

### Modification

- Keep ownership of newly created compressors until they are attached to
a stream.
- Release compressors that are not attached after either `writeHeaders`
overload returns or throws.
- Release partially initialized compressors if header preparation fails.
- Add regression tests for both overloads covering missing streams,
synchronous and asynchronous failures, and existing streams in invalid
states.

### Result

Failed HEADERS writes no longer leave compression `EmbeddedChannel`s
open, while compressors attached to streams continue to be released by
the existing stream-removal path.

### Testing

- `./mvnw -pl codec-http2 -Dtest=CompressorHttp2ConnectionEncoderTest
test`
- `./mvnw -pl codec-http2
-Dtest=CompressorHttp2ConnectionEncoderTest,DataCompressionHttp2Test
test`
- `./mvnw -pl codec-http2 test`

Co-authored-by: Gimin Kim <[email protected]>
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.

3 participants