Skip to content

Auto-port 5.0: HttpServerCodec: do not consume the method queue for 1xx interim responses - #17202

Merged
chrisvest merged 2 commits into
5.0from
auto-port-pr-17182-to-5.0
Aug 3, 2026
Merged

chrisvest merged 2 commits into
5.0from
auto-port-pr-17182-to-5.0

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port of #17182 to 5.0
Cherry-picked commit: ae41417


Motivation

Resolves #17181.

#12918 stopped 1xx interim responses from consuming a queue entry in HttpClientCodec and HttpContentEncoder, but HttpServerCodec was left out.

isContentAlwaysEmpty(HttpResponse) in HttpServerCodec polls the request method queue for every response it encodes:

@Override
protected boolean isContentAlwaysEmpty(HttpResponse msg) {
    methodFlag = pollMethod();
    return methodFlag == METHOD_FLAG_HEAD || super.isContentAlwaysEmpty(msg);
}

It is invoked for every HttpResponse on both encoder paths — encodeFullHttpMessage() and encodeInitHttpMessage() in HttpObjectEncoder. An interim response is not the final response to the queued request, so consuming an entry shifts the queue by one and the wrong method gets paired with the final response.

Both failure modes are reachable from first-party handlers: HttpServerExpectContinueHandler and HttpObjectAggregator write 100 Continue through this encoder.

Modification

Skip pollMethod() when the response status class is INFORMATIONAL and delegate to the super method, mirroring the guard already present in isContentAlwaysEmpty(HttpMessage) in HttpClientCodec.

methodFlag is intentionally left untouched on the interim path. sanitizeHeadersBeforeEncode() reads it for the CONNECT check, but that branch also requires codeClass() == SUCCESS, which a 1xx response never satisfies.

Result

Interim responses no longer shift the method queue, so HEAD and CONNECT are paired with their own final response.

Encoder output for the two broken cases, measured with the tests added here:

scenario before after
HEAD /a, then 103, then final 200 OK with content HTTP/1.1 200 OK\r\ncontent-length: 4\r\n\r\nbody HTTP/1.1 200 OK\r\ncontent-length: 4\r\n\r\n
pipelined GET /a + HEAD /b, then 103, then /a's 200 OK with content HTTP/1.1 200 OK\r\ncontent-length: 6\r\n\r\n HTTP/1.1 200 OK\r\ncontent-length: 6\r\n\r\nbody-a
HEAD / with Upgrade, then 101 HTTP/1.1 101 Switching Protocols\r\nconnection: upgrade\r\nupgrade: websocket\r\n\r\n unchanged

The first row is a HEAD response carrying a body, which per RFC 9110 section 9.3.2 must never happen — on a keep-alive connection the peer reads those bytes as the start of the next response. The second is a non-HEAD response losing its body while keeping Content-Length, leaving the peer waiting for six bytes that never arrive.

Sequential request/response traffic recovers on its own, since an empty queue falls back to METHOD_FLAG_OTHER. Corruption needs either a 1xx preceding a HEAD response, or pipelining combined with a 1xx.

101 is included in INFORMATIONAL and is therefore covered by the guard, with no change on the wire. After switching protocols the codec is removed from the pipeline — by upgradeFrom() in HttpServerCodec for h2c, and by WebSocketServerHandshaker for WebSocket — so the entry left behind is discarded together with the handler. The third row above pins this.

This also corrects CONNECT: previously a 1xx could consume the CONNECT entry, so the final 2xx response missed the Transfer-Encoding stripping in sanitizeHeadersBeforeEncode().

codec-http passes in full: 8973 tests, 0 failures.

…sponses (#17182)

### Motivation

Resolves #17181.

#12918 stopped 1xx interim responses from consuming a queue entry in
`HttpClientCodec` and `HttpContentEncoder`, but `HttpServerCodec` was
left out.

`isContentAlwaysEmpty(HttpResponse)` in `HttpServerCodec` polls the
request method queue for every response it encodes:

```java
@OverRide
protected boolean isContentAlwaysEmpty(HttpResponse msg) {
    methodFlag = pollMethod();
    return methodFlag == METHOD_FLAG_HEAD || super.isContentAlwaysEmpty(msg);
}
```

It is invoked for every `HttpResponse` on both encoder paths —
`encodeFullHttpMessage()` and `encodeInitHttpMessage()` in
`HttpObjectEncoder`. An interim response is not the final response to
the queued request, so consuming an entry shifts the queue by one and
the wrong method gets paired with the final response.

Both failure modes are reachable from first-party handlers:
`HttpServerExpectContinueHandler` and `HttpObjectAggregator` write `100
Continue` through this encoder.

### Modification

Skip `pollMethod()` when the response status class is `INFORMATIONAL`
and delegate to the super method, mirroring the guard already present in
`isContentAlwaysEmpty(HttpMessage)` in `HttpClientCodec`.

`methodFlag` is intentionally left untouched on the interim path.
`sanitizeHeadersBeforeEncode()` reads it for the CONNECT check, but that
branch also requires `codeClass() == SUCCESS`, which a 1xx response
never satisfies.

### Result

Interim responses no longer shift the method queue, so HEAD and CONNECT
are paired with their own final response.

Encoder output for the two broken cases, measured with the tests added
here:

| scenario | before | after |
|---|---|---|
| `HEAD /a`, then `103`, then final `200 OK` with content | `HTTP/1.1
200 OK\r\ncontent-length: 4\r\n\r\nbody` | `HTTP/1.1 200
OK\r\ncontent-length: 4\r\n\r\n` |
| pipelined `GET /a` + `HEAD /b`, then `103`, then `/a`'s `200 OK` with
content | `HTTP/1.1 200 OK\r\ncontent-length: 6\r\n\r\n` | `HTTP/1.1 200
OK\r\ncontent-length: 6\r\n\r\nbody-a` |
| `HEAD /` with `Upgrade`, then `101` | `HTTP/1.1 101 Switching
Protocols\r\nconnection: upgrade\r\nupgrade: websocket\r\n\r\n` |
unchanged |

The first row is a HEAD response carrying a body, which per RFC 9110
section 9.3.2 must never happen — on a keep-alive connection the peer
reads those bytes as the start of the next response. The second is a
non-HEAD response losing its body while keeping `Content-Length`,
leaving the peer waiting for six bytes that never arrive.

Sequential request/response traffic recovers on its own, since an empty
queue falls back to `METHOD_FLAG_OTHER`. Corruption needs either a 1xx
preceding a HEAD response, or pipelining combined with a 1xx.

101 is included in `INFORMATIONAL` and is therefore covered by the
guard, with no change on the wire. After switching protocols the codec
is removed from the pipeline — by `upgradeFrom()` in `HttpServerCodec`
for h2c, and by `WebSocketServerHandshaker` for WebSocket — so the entry
left behind is discarded together with the handler. The third row above
pins this.

This also corrects CONNECT: previously a 1xx could consume the CONNECT
entry, so the final 2xx response missed the `Transfer-Encoding`
stripping in `sanitizeHeadersBeforeEncode()`.

`codec-http` passes in full: 8973 tests, 0 failures.

Co-authored-by: Norman Maurer <[email protected]>
(cherry picked from commit ae41417)
@chrisvest
chrisvest enabled auto-merge (squash) August 3, 2026 18:53
@testlens-app

testlens-app Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

🚨 TestLens detected 2 failed tests 🚨

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 / macos-aarch64-java25-boringssl build > Netty/Transport/Native/KQueue

Test Runs Flakiness
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendDirectByteBuf(TestInfo) ❌ 1% 🟡
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendWithConnect(TestInfo) ❌ 3% 🟡

🏷️ Commit: dcdff74
▶️ Tests: 40635 executed
⚪️ Checks: 12/12 completed

Test Failures

KQueueDatagramUnicastIPv6MappedTest > testSimpleSendDirectByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-aarch64-java25-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.testSimpleSendDirectByteBuf(DatagramUnicastTest.java:89)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$1.run(DatagramUnicastTest.java:82)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$1.run(DatagramUnicastTest.java:79)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendDirectByteBuf(DatagramUnicastTest.java:79)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendWithConnect(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-aarch64-java25-boringssl build)
org.opentest4j.AssertionFailedError
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendWithConnect0(DatagramUnicastTest.java:414)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendWithConnect(DatagramUnicastTest.java:375)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendWithConnect(DatagramUnicastTest.java:211)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$7.run(DatagramUnicastTest.java:204)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$7.run(DatagramUnicastTest.java:201)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendWithConnect(DatagramUnicastTest.java:201)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)

Muted Tests

Select tests to mute in this pull request:

  • KQueueDatagramUnicastIPv6MappedTest > testSimpleSendDirectByteBuf(TestInfo)
  • KQueueDatagramUnicastIPv6MappedTest > testSimpleSendWithConnect(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.

@chrisvest
chrisvest disabled auto-merge August 3, 2026 20:47
@chrisvest
chrisvest merged commit c6e285e into 5.0 Aug 3, 2026
12 of 13 checks passed
@chrisvest
chrisvest deleted the auto-port-pr-17182-to-5.0 branch August 3, 2026 20:47
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