Repository navigation
Auto-port 5.0: HTTP: Release content encoder after header mutation failure - #17293
Merged
Merged
Conversation
### Motivation `HttpContentEncoder` stored the `EmbeddedChannel` returned by `beginEncode()` in its `encoder` field before mutating the response headers. If a mutation failed, for example because the response used `ReadOnlyHttpHeaders`, the newly created content encoder remained open. With assertions disabled, a subsequent response could overwrite the field. Handler removal or channel shutdown would then release only the replacement encoder, leaving the first encoder without deterministic cleanup. ### Modification - Keep a newly created content encoder locally owned while response headers and streaming state are prepared. - Transfer ownership to the handler field only when encoding can proceed. - Call `finishAndReleaseAll()` when preparation or synchronous full-response encoding fails before ownership is retained. - Add a regression test that verifies the failed encoder is closed and the handler remains usable for the next response. ### Result Header mutation failures no longer leave a content encoder open or allow it to be lost on a later response. Successful full and streaming response encoding remains unchanged. ### Testing - `./mvnw -pl codec-http -Dtest=HttpContentEncoderTest#testHeaderMutationFailureReleasesContentEncoder test` - `./mvnw -pl codec-http -Dtest=HttpContentEncoderTest#testHeaderMutationFailureReleasesContentEncoder -DargLine.common=-da test` - `./mvnw -pl codec-http test` — 8,983 tests, 0 failures, 0 errors, 4 skipped (cherry picked from commit 039add4)
🚨 TestLens detected 4 failed tests 🚨Here is what you can do:
Test SummaryBuild PR / linux-x86_64-java25 build > Netty/Codec/HTTP2
Build PR / linux-x86_64-java25-graal build > Netty/Codec/HTTP2
Build PR / macos-aarch64-java25-boringssl build > Netty/Transport/Native/KQueue
🏷️ Commit: 0ea40ee Test FailuresDataCompressionHttp2Test > encodingTooBigMessage(int, AsciiString) > [4] 0, snappy (Netty/Codec/HTTP2 in Build PR / linux-x86_64-java25 build)
DataCompressionHttp2Test > encodingTooBigMessage(int, AsciiString) > [4] 0, snappy (Netty/Codec/HTTP2 in Build PR / linux-x86_64-java25-graal build)
DataCompressionHttp2Test > encodingTooBigMessage(int, AsciiString) > [8] 10, snappy (Netty/Codec/HTTP2 in Build PR / linux-x86_64-java25-graal build)
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendDirectByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-aarch64-java25-boringssl build)Muted TestsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app. |
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.
Auto-port of #17292 to 5.0
Cherry-picked commit: 039add4
Motivation
HttpContentEncoderstored theEmbeddedChannelreturned bybeginEncode()in itsencoderfield before mutating the response headers. If a mutation failed, for example because the response usedReadOnlyHttpHeaders, the newly created content encoder remained open.With assertions disabled, a subsequent response could overwrite the field. Handler removal or channel shutdown would then release only the replacement encoder, leaving the first encoder without deterministic cleanup.
Modification
finishAndReleaseAll()when preparation or synchronous full-response encoding fails before ownership is retained.Result
Header mutation failures no longer leave a content encoder open or allow it to be lost on a later response. Successful full and streaming response encoding remains unchanged.
Testing
./mvnw -pl codec-http -Dtest=HttpContentEncoderTest#testHeaderMutationFailureReleasesContentEncoder test./mvnw -pl codec-http -Dtest=HttpContentEncoderTest#testHeaderMutationFailureReleasesContentEncoder -DargLine.common=-da test./mvnw -pl codec-http test— 8,983 tests, 0 failures, 0 errors, 4 skipped