GeezerVison is showing github.com — Netty HTTP/2 client livelock — reentrant flush during pipeline setup · Issue #17256 · netty/netty
Netty HTTP/2 client livelock — reentrant flush during pipeline setup #17256DescriptionSummary: A ServiceTalk HTTP/2 (and gRPC, which mandates H2) client connection can permanently wedge one of Netty's IO event-loop threads at ~100% CPU during initial pipeline setup, on an apparently healthy, reachable destination. Once wedged, the thread never recovers for the life of the process — only a full JVM restart clears it. Poisoning accumulates over the process's uptime as more first-time connections are attempted.
Versions:
- Netty: 4.2.16.Final
- ServiceTalk: 0.42.64
- OS: macOS (kqueue-based Netty transport observed in traces; mechanism is generic to the epoll/kqueue Netty transports, not macOS-specific)
Confirmed stack signature (captured via jcmd Thread.print, identical pattern reproduced independently on two separate occasions against two different downstream services):
io.netty.handler.ssl.SslHandler.wrap
io.netty.handler.ssl.SslHandler.wrapAndFlush
io.netty.handler.ssl.SslHandler.flush
io.netty.channel.AbstractChannelHandlerContext.flush
io.netty.handler.codec.http2.Http2ConnectionHandler.flush
io.netty.handler.codec.http2.Http2ConnectionHandler.channelWritabilityChanged
io.netty.channel.AbstractChannelHandlerContext.fireChannelWritabilityChanged
... (ChannelOutboundBuffer / kqueue write plumbing) ...
io.netty.handler.ssl.SslHandler.forceFlush
io.netty.handler.ssl.SslHandler.wrapAndFlush
io.netty.handler.ssl.SslHandler.flush
io.netty.channel.AbstractChannelHandlerContext.flush
io.netty.handler.codec.http2.Http2ConnectionHandler.flush
io.netty.handler.codec.http2.Http2FrameCodec.tryExpandConnectionFlowControlWindow
io.netty.handler.codec.http2.Http2FrameCodec.userEventTriggered
io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.sendPrefaceIfNeeded
io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.<init>
io.netty.handler.codec.http2.Http2ConnectionHandler.handlerAdded
io.netty.handler.codec.http2.Http2FrameCodec.handlerAdded
io.netty.channel.AbstractChannelHandlerContext.callHandlerAdded
io.netty.channel.DefaultChannelPipeline.callHandlerAdded0
io.netty.channel.DefaultChannelPipeline.internalAdd / addLast
io.servicetalk.http.netty.H2ClientParentChannelInitializer.init
io.servicetalk.http.netty.H2ClientParentConnectionContext$1.handleSubscribe
... (ServiceTalk Single subscription plumbing) ...
io.servicetalk.http.netty.AlpnChannelSingle$AlpnChannelHandler.configurePipeline
io.netty.handler.ssl.ApplicationProtocolNegotiationHandler.userEventTriggered
io.netty.handler.ssl.SslHandler.setHandshakeSuccess
... (SSL unwrap/decode plumbing) ...
io.netty.channel.kqueue.KQueueIoHandler.processReady / run
io.netty.channel.SingleThreadIoEventLoop.run
Trigger point: happens during Http2ConnectionHandler.handlerAdded, specifically inside PrefaceDecoder.sendPrefaceIfNeeded →
Http2FrameCodec.tryExpandConnectionFlowControlWindow → flush. This fires only on a brand-new connection's H2 pipeline setup
(AlpnChannelSingle/H2ClientParentChannelInitializer), i.e. the first time a client connects to a given host — not on subsequent requests over an
already-established connection.
Suspected mechanism (not confirmed upstream): Http2ConnectionHandler.flush(ctx) calls encoder.flowController().writePendingBytes() (guarded against reentrancy by an inWritePendingBytes flag) and then calls ctx.flush(). If that ctx.flush() synchronously fires channelWritabilityChanged — which can happen during initial pipeline setup when channel writability flips — channelWritabilityChanged() calls flush(ctx) again, but by then the inWritePendingBytes guard has already reset to false, so the reentrancy guard doesn't catch this outer cycle. Since tryExpandConnectionFlowControlWindow invokes flush(ctx) from inside handlerAdded, this looks like an unguarded reentrancy gap in Netty's own H2 codec — not something callable code can defend against.
Confirmed via two independent thread dumps ~46s apart: three IO threads (servicetalk-global-io-executor-1-{5,6,7}) each accumulated exactly ~45.5s of CPU time across that ~45.67s window — i.e. continuous ~100% CPU utilization, Thread.State: RUNNABLE throughout, no decline. They had already been spinning since near process startup and showed no sign of self-terminating.
What's been ruled out:
- Not a network/host-health issue. A destination confirmed independently healthy and fast (curl+nghttp2: full TCP+TLS+ALPN→h2+HTTP/2 request/response in 294ms) still triggered this via our Netty/ServiceTalk client — the destination is fine; this is in-process.
- Not a DNS/reachability issue — the failure point is after successful TCP connect, TLS handshake, and ALPN negotiation of "h2"; a genuinely unreachable host fails cleanly before ever reaching this code.
- Not tied to a specific auth layer — traced the auth path (Apple-internal Daiquiri system-account JWT) and confirmed it's a purely local, in-process JWT signing operation from an already-loaded key (no network call), so it can't independently trigger a second H2 handshake.
- Not fixable by forcing HTTP/1.1 for gRPC clients — gRPC's wire protocol mandates HTTP/2; the client builder API has zero protocol-selection surface for gRPC, and the default builder implementation hardcodes H2 with no override point.
- Not fixed by a Netty version bump — Http2FrameCodec.java/Http2ConnectionHandler.java are byte-identical between 4.2.16.Final, 4.2.17.Final, and the 4.2 branch HEAD as of this investigation.
- Not purely a concurrency issue — reducing concurrency (down to fully serialized, one connection attempt at a time) did not prevent it from firing on the very first attempt; each occurrence looks like an independent, per-connection event rather than a race between simultaneous connections.
- No existing matching issue found in netty/netty or apple/servicetalk issue trackers (searched for tryExpandConnectionFlowControlWindow, PrefaceDecoder, sendPrefaceIfNeeded, channelWritabilityChanged+flush/spin/livelock). Closest related-but-different issue: HTTP/2 client OOM:
DefaultHttp2RemoteFlowController spins writing empty DATA frames when CoalescingBufferQueue readableBytes desyncs #16946 (a different H2 flow-control spin, already fixed in 4.2.16.Final, different trigger/code path).
Impact: once triggered, the affected IO thread is permanently lost for the life of the process (no timeout recovers it — it's CPU-bound execution, not a blocked I/O wait, so nothing can interrupt it short of process termination). If the poisoned thread pool is shared with the process's own inbound request handling, the whole application's responsiveness degrades as more threads get poisoned over time. ActivityZohaibcode740 commented on Aug 12, 2026 Thanks for linking this PR. The reentrant flush() path addressed here matches the failure mechanism observed in my report, particularly the channelWritabilityChanged() → flush() cycle during initial HTTP/2 pipeline setup.
I appreciate the fix and the investigation. Zohaibcode740 commented on Aug 12, 2026 The issue can be addressed by tracking when Http2ConnectionHandler is already performing a flush and preventing channelWritabilityChanged() from triggering a nested flush() during that operation. The added regression test for a synchronous writability change during ChannelHandlerContext.flush() also covers the reentrant path described in the issue.
This should prevent the HTTP/2 event-loop livelock caused by the reentrant flush cycle during initial pipeline setup. normanmaurer commented on Aug 12, 2026 added a commit that references this issue on Aug 12, 2026This issue will close once commit 1ec9af2 is merged into the '4.2' branch.1ec9af2 added 2 commits that reference this issue on Aug 12, 2026This issue will close once commit 48c8075 is merged into the '4.2' branch.48c8075 This issue will close once commit 03447d5 is merged into the '4.2' branch.03447d5 bryce-anderson commented on Aug 13, 2026 @vitolibrarius, by chance do you have the full stack trace handy? I'm specifically interested in the ... (ChannelOutboundBuffer / kqueue write plumbing) ... parts. It would also be super helpful to have the line numbers, if they're available. Zohaibcode740 commented on Aug 13, 2026 @bryce-anderson Thanks for looking into this.
I can provide the full thread dump from the affected event-loop thread. The relevant stack shows the reentrant path through:
SslHandler.wrapAndFlush
→ SslHandler.flush
→ Http2ConnectionHandler.flush
→ Http2ConnectionHandler.channelWritabilityChanged
→ AbstractChannelHandlerContext.flush
The occurrence was observed during initial HTTP/2 pipeline setup after TLS/ALPN negotiation.
I’ll provide the complete stack trace and line numbers here so the ChannelOutboundBuffer / kqueue portion can be inspected as well. bryce-anderson commented on Aug 13, 2026 Thanks @Zohaibcode740. I can see that path in the original post but the exact lines would be helpful, as well as the kqueue flushing lines. The reason I'm interested is that if it were truly reentrant, I'd expect a stack overflow and not a maxed out CPU. They're not mutually exclusive (there are a few places we catch a Throwable and act where we probably shouldn't), but knowing the line numbers would make it more clear. Reacted by Syed Zohaib Ali bryce-anderson commented on Aug 17, 2026 Reacted by Syed Zohaib Ali added 2 commits that reference this issue on Oct 24, 2026This issue will close once commit 67c4594 is merged into the '4.2' branch.67c4594 This issue will close once commit f26202e is merged into the '4.2' branch.f26202e
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|