GeezerVison is showing github.com — HTTP2 server occasionally sends SETTINGS ack as first frame · Issue #16142 · netty/netty
HTTP2 server occasionally sends SETTINGS ack as first frame #16142DescriptionAleph's test suite occasionally flakes with the following error:
io.netty.handler.codec.http2.Http2Exception: First received frame was not SETTINGS. Hex dump for first 5 bytes: 0000000401
The error message is a bit misleading: It is in fact a SETTINGS frame but with the ACK bit set (see 8f33488 - maybe the error message could be improved here). I suspect that it's a race condition in which the server receives the client's initial SETTINGS frame before having sent its own and then immediately sends the ack frame. I've tried to construct a reproducer for this but was unsuccessful so far but wanted to share it already - maybe you can figure this out more quickly 🙏 Activitynormanmaurer commented on Jan 19, 2026 DerGuteMoritz commented on Jan 19, 2026 DerGuteMoritz commented on Jan 19, 2026 Ah perhaps I should also mention that we're using Http2MultiplexHandler. If you need more details, let me know! DerGuteMoritz commented on Jan 19, 2026 Another possibly relevant piece of info: This happens with TLSv1.3 - could Early Data be the culprit? DerGuteMoritz commented on Jan 19, 2026 FWIW: I just switched the CI job which ran into this error around 80% of the time to use TLSv1.2 instead of TLSv1.3 and so far, it hasn't happened again. Will re-run it a few times now to further confirm (it runs around 1 hour, so this will take a while). DerGuteMoritz commented on Jan 19, 2026 OK, seems I just got lucky. It happened again on the second run, so TLSv1.3 Early Data can be safely ruled out I'd say. normanmaurer commented on Feb 18, 2026 I was not able to reproduce this yet :/ normanmaurer commented on Mar 3, 2026 @DerGuteMoritz maybe you have any more details I can use to reproduce it ? DerGuteMoritz commented on Mar 3, 2026 Here's what the connection and stream channel pipelines look like:
4407 tid=38 DEBUG http2 - server conn chan pipeline: DefaultChannelPipeline
Handlers:
channel-tracker: netty$channel_tracking_handler$reify__17514 (#4301250)
ssl-handler: SslHandler (#287745061)
apn-handler: ApnHandler (#978339122)
http2-frame-codec: Http2FrameCodec (#2004107349)
multiplex: Http2MultiplexHandler (#2050400456)
conn-ex-handler: common$add_exception_handler$reify__17810 (#1586836519)
4438 tid=38 DEBUG http2 - server stream chan pipeline: AbstractHttp2StreamChannel$3
Handlers:
AlephChannelInitializer#0: AlephChannelInitializer (#219959979)
streamer: ChunkedWriteHandler (#579726404)
handler: http2$server_handler$reify__18454 (#626110278)
AlephChannelInitializer is a pretty simple shim.
Does anything jump out? DerGuteMoritz commented on Mar 16, 2026 In the meantime, I received a patch which claims to work around the issue and contains a possible explanation for it. Quoting the pertinent part:
;; Flush the HTTP/2 connection preface (magic + initial SETTINGS) that was
;; written by Http2ConnectionHandler.sendPreface() during handlerAdded.
;; When Http2FrameCodec is added to an already-active pipeline (the normal
;; case for both client post-SSL-handshake and server ALPN paths),
;; channelActive is never replayed, so the flushPreface guard in
;; PrefaceDecoder.channelActive never fires. Without this explicit flush,
;; the preface sits in SslHandler.pendingUnencryptedWrites and under
;; certain allocator/timing conditions (e.g., unpooled allocator on
;; JDK 21), a SETTINGS ACK can be flushed before the initial SETTINGS,
;; causing the peer to reject the connection.
;; See https://github.com/netty/netty/issues/12089
(let [ch (.channel pipeline)]
(when (.isActive ch)
(.flush ch)))
I haven't yet verified this but wanted to share with you already. Does it make sense? normanmaurer commented on Mar 16, 2026 @DerGuteMoritz hmm not really as the SslHandler would just put the other writes behind it. DerGuteMoritz commented on Mar 17, 2026 @normanmaurer Right, that's what I would have thought, as well. In the meantime, the author informed me that the patch was LLM-assisted so at least the explanation in the code comment might just be hallucination. However, they also confirmed that the patch did empirically fix the issue for them when the tests were previously failing consistently with Netty 1.2 in combination with JDK 21 and the adaptive allocator. This might have just been a coincidence, though. At least I couldn't reproduce it any better so far... normanmaurer commented on Apr 14, 2026 DerGuteMoritz commented on Apr 15, 2026 @normanmaurer Ah very interesting, thanks for notifying me! However, IIUIC that patch pertains to the client's behavior, right? In the cases we encountered so far, it was the server which sent something other than the preface as the initial message. Somewhat stabbing in the dark: Perhaps the same change needs to be applied to Http2ConnectionHandler#bind? DerGuteMoritz commented on May 5, 2026 @normanmaurer Just saw the release notes for 4.2.13 / 4.1.133 and found that you implemented my suggestion above with #16667, right? Thanks a lot 👍 Will let you know if it happens again after updating to the new version. In the meantime, feel free to close this issue. DerGuteMoritz commented on Jun 5, 2026
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|