Skip to content

Auto-port 5.0: HTTP: Preserve encoder state after header encoding failures - #17274

Merged
normanmaurer merged 2 commits into
5.0from
auto-port-pr-17271-to-5.0
Aug 13, 2026
Merged

normanmaurer merged 2 commits into
5.0from
auto-port-pr-17271-to-5.0

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port of #17271 to 5.0
Cherry-picked commit: dd7c9dc


Motivation:

encodeInitHttpMessage() updated the encoder state before running header sanitization and encoding. If either step threw, the allocated buffer was released but the encoder remained in a content state even though no output had been produced. A subsequent valid response was then rejected with unexpected message type.

This can be reproduced without a fatal error by encoding a 204 No Content response backed by ReadOnlyHttpHeaders. Sanitization fails with UnsupportedOperationException, and the next response fails because the encoder is still in state 3.

#17089 made the header buffer exception-safe, but its regression test ended the channel immediately after the failure and did not exercise another response.

Modification:

  • Compute the next content state in a local variable.
  • Commit it to the encoder only after header sanitization and encoding complete successfully.
  • Add a regression test for a sanitization failure and extend the existing header encoding failure test to verify that a valid response can still be encoded afterward.

Result:

An initial-message header failure no longer leaves the encoder unusable. Successful encoding and wire output are unchanged.

Verification:

./mvnw -pl codec-http test

8,982 tests run, 0 failures, 0 errors, 4 skipped.

Motivation:

`encodeInitHttpMessage()` updated the encoder state before running
header sanitization and encoding. If either step threw, the allocated
buffer was released but the encoder remained in a content state even
though no output had been produced. A subsequent valid response was then
rejected with `unexpected message type`.

This can be reproduced without a fatal error by encoding a `204 No
Content` response backed by `ReadOnlyHttpHeaders`. Sanitization fails
with `UnsupportedOperationException`, and the next response fails
because the encoder is still in state 3.

#17089 made the header buffer exception-safe, but its regression test
ended the channel immediately after the failure and did not exercise
another response.

Modification:

- Compute the next content state in a local variable.
- Commit it to the encoder only after header sanitization and encoding
complete successfully.
- Add a regression test for a sanitization failure and extend the
existing header encoding failure test to verify that a valid response
can still be encoded afterward.

Result:

An initial-message header failure no longer leaves the encoder unusable.
Successful encoding and wire output are unchanged.

Verification:

`./mvnw -pl codec-http test`

8,982 tests run, 0 failures, 0 errors, 4 skipped.

(cherry picked from commit dd7c9dc)
@testlens-app

testlens-app Bot commented Aug 13, 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-java25 build > Netty/Codec/HTTP2

Test Runs Flakiness
DataCompressionHttp2Test > encodingTooBigMessage(int, AsciiString) > [4] 0, snappy ❌ 1% 🟡

🏷️ Commit: 6ec174c
▶️ Tests: 227123 executed
⚪️ Checks: 12/12 completed

Test Failures

DataCompressionHttp2Test > encodingTooBigMessage(int, AsciiString) > [4] 0, snappy (Netty/Codec/HTTP2 in Build PR / linux-x86_64-java25 build)
org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:31)
	at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:183)
	at io.netty.handler.codec.http2.DataCompressionHttp2Test$5.call(DataCompressionHttp2Test.java:254)
	at io.netty.handler.codec.http2.DataCompressionHttp2Test$5.call(DataCompressionHttp2Test.java:251)
	at io.netty.handler.codec.http2.DataCompressionHttp2Test.testEncodingMessage(DataCompressionHttp2Test.java:309)
	at io.netty.handler.codec.http2.DataCompressionHttp2Test.encodingTooBigMessage(DataCompressionHttp2Test.java:251)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at java.base/java.util.Optional.ifPresent(Optional.java:178)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:186)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:186)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:186)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.stream.SpinedBuffer$1Splitr.forEachRemaining(SpinedBuffer.java:364)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:803)
	at java.base/java.util.stream.ReferencePipeline$7$1FlatMap.accept(ReferencePipeline.java:293)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:153)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:176)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:632)
	at java.base/java.util.stream.ReferencePipeline$7$1FlatMap.accept(ReferencePipeline.java:293)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1716)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:153)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:176)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:632)
	at java.base/java.util.stream.ReferencePipeline$7$1FlatMap.accept(ReferencePipeline.java:293)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1716)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:153)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:176)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:632)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:511)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.tryRemoveAndExec(ForkJoinPool.java:1490)
	at java.base/java.util.concurrent.ForkJoinPool.helpJoin(ForkJoinPool.java:2248)
	at java.base/java.util.concurrent.ForkJoinTask.awaitDone(ForkJoinTask.java:499)
	at java.base/java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:666)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:511)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1450)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2019)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
expected actual
true false

Muted Tests

Select tests to mute in this pull request:

  • DataCompressionHttp2Test > encodingTooBigMessage(int, AsciiString)

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.

@normanmaurer
normanmaurer merged commit d654d03 into 5.0 Aug 13, 2026
12 of 13 checks passed
@normanmaurer
normanmaurer deleted the auto-port-pr-17271-to-5.0 branch August 13, 2026 09:45
@normanmaurer normanmaurer added this to the 5.0.0.Final milestone Aug 13, 2026
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