Repository navigation
Description
Summary
The non-gRPC HTTP/2 path multiplexes every stream over a single shared connection channel, with stream identity carried in an x-http2-stream-id header rather than by the channel itself. Netty's Http2MultiplexHandler model — where each stream is a child channel — is the architecturally correct end state and would make a whole class of stream-routing bugs unrepresentable rather than merely fixed.
This is tracked from the TODO(jamesdbloom) at mockserver/mockserver-netty/src/main/java/org/mockserver/netty/unification/PortUnificationHandler.java:447. Filing it so the deferred work is visible: every issue that motivated it (#2641, #2667) is now closed, so the TODO was the only remaining record.
Not a correctness prerequisite
To be clear about priority: the bug that made this urgent is fixed. #2667 (a chunk for one stream being written to a different, already-closed stream) is resolved on the shared-connection architecture by StreamRoutingHttpToHttp2ConnectionHandler + StreamAddressedHttpContent, which address each data write to its originating stream instead of relying on the codec's single mutable currentStreamId. There is no known open correctness defect requiring this migration.
Why it is still worth doing
The current design keeps working by convention — every outbound write must remember to carry its stream id. Http2StreamIdAuditHandler exists precisely because a response head that forgets is silently mis-routed onto a new server-initiated stream, producing a hang the client sees and the server never reports. That is a warning about a design that is easy to get wrong, and it only covers heads, not content frames.
Under the multiplex model the child channel carries stream identity structurally, so:
- a write cannot be mis-addressed, because there is nothing to address;
- the audit handler and the
x-http2-stream-idheader contract become unnecessary; - fully-interleaved concurrent streaming — still a limitation today — falls out for free.
Known blast radius
This was scoped while fixing #2667 and is genuinely large; the whole non-gRPC pipeline assumes one channel per connection:
HttpRequestHandlerand everything sharing the connection channel- the
x-http2-stream-idheader contract andHttp2StreamIds Http2StreamIdAuditHandler(removable)StreamRoutingHttpToHttp2ConnectionHandler/StreamAddressedHttpContent(removable — superseded)- the keep-alive /
ctx.close()handling inHttpSseResponseActionHandler.finishStreamfrom Streaming httpLlmResponse/httpSseResponse closes the connection immediately despite sending Connection: keep-alive, and intermittently takes down sibling HTTP/2 streams #2641, which must never close the shared parent - WebSocket, dashboard and MCP handlers on the shared channel
- the h2c upgrade path and the ALPN/TLS switch in
PortUnificationHandler
The gRPC path (switchToHttp2Multiplex) already uses Http2FrameCodec + Http2MultiplexHandler, so it is the working reference for the target design.
Suggested approach
Not a single change. Likely: migrate behind a flag with both paths coexisting, port the handlers that assume a connection-scoped channel, then remove the header contract and the audit handler once the multiplex path is the only one. Concurrent interleaved streaming is the acceptance test — it is the case that does not work today.
Activity
docs(netty): point the HTTP/2 multiplex TODO at its tracked issue
modelpath-dev commentedon Sep 10, 2026
I will take this issue. Please assign it to me.
The current implementation uses a shared connection channel with stream identity in headers. The goal is to migrate to
Http2MultiplexHandler, where each stream is a child channel. I will start by examining thePortUnificationHandler.javaat line 447, as noted in the TODO. The first step is to replace the existing stream handling logic withHttp2MultiplexHandler. I will ensure that the stream identity is correctly managed by the child channels, removing the need forx-http2-stream-idheaders and related handlers. This should simplify the architecture and prevent mis-routing issues.jamesdbloom commentedon Sep 11, 2026
Done. The
Http2FrameCodec+Http2MultiplexHandlerpipeline is now the only HTTP/2 server pipeline, for bothh2andh2c, with no configuration flag — every stream gets its own child channel.What actually took the time
The multiplexed pipeline already existed here, used only when
grpcBidiStreamingEnabledwas set. That made it a quiet corner of the codebase, and quiet corners hide a specific kind of bug: connection-level machinery that does nothing useful on a per-stream channel and says nothing about it. Six of those were found and fixed before the switch, each one on its own, each one already reachable today by anyone running gRPC bidi streaming:Every one of them failed silently. Nothing threw, nothing was logged, and the server believed it had acted each time. The switch itself is 822de0b; ae25170 removes the old machinery.
Two more surfaced during the switch, both caught by review rather than by the test suite:
Configurationwhen it moved, so amaxGrpcMessageSizeset on a Configuration instance stopped being enforced over HTTP/2 while HTTP/1.1 carried on honouring itcontent-encodingheader, so an expectation matching on that header stopped matching — HTTP/1.1 has long kept a copy of the headers Netty removes, and the stream pipeline now does the sameThe second of those was only visible once the test command was corrected:
mvn testexcludes*IntegrationTest, so it runs about 1218 tests; the real gate runs 2257. The regression sat inside that gap.What changes for users
One thing, and it is called out in the changelog: over HTTP/2,
closeSocket/closeChannelnow ends only the requesting stream instead of tearing down the connection and every concurrent request on it. That is the correct semantic when a connection carries many requests at once, and it is what the same expectation already did over HTTP/1.1. If you want the connection genuinely aborted, theresetMidResponsechaos fault still does that — and now does it properly rather than degrading into a stream reset.Everything else is a fix for something that was silently broken. Requests match the same way, responses come back the same way, expectations are written the same way, and HTTP/1.1 and HTTP/3 are untouched.
Performance
Honestly: not yet measured under concurrency. A channel per stream allocates more than a shared pipeline did, and that question deserves a real answer rather than a guess. Two attempts to measure it locally failed — the first produced a physically impossible result (a million requests a second, a 95 nanosecond p95) because it counted requests it had assumed rather than completed, and recommended shipping on the strength of it. A self-validating benchmark now runs on the perf pipeline (dbdbec5): it records throughput and percentiles across 1, 10 and 100 concurrent streams, never gates a build on the numbers, and fails loudly if the measurement itself cannot be trusted. A threshold will follow once there is enough history to set one against something real.
jamesdbloom commentedon Sep 12, 2026
Sorry @modelpath-dev, I didn't see your comment until after I had already started working on a solution, so this is now done. Happy to leave the next similar issue to you.
test(netty): lock HTTP/2 conformance with an independent client and r…
modelpath-dev commentedon Oct 24, 2026
@jamesdbloom no worries at all, and thanks for writing up the six fixes, that was a good read. Happy to take the next one like this.