GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #17256

New issue
Copy link
New issue
Copy link
Closed
#17266
Closed
Netty HTTP/2 client livelock — reentrant flush during pipeline setup#17256
#17266
Copy link
Milestone
4.2.18.Final

Description

@vitolibrarius
vitolibrarius
opened on Aug 11, 2026
Issue body actions

Summary: 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.

Activity

  1. Zohaibcode740 commented on Aug 12, 2026

    @Zohaibcode740
    Zohaibcode740
    on Aug 12, 2026
    More actions

    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.

  2. Zohaibcode740 commented on Aug 12, 2026

    @Zohaibcode740
    Zohaibcode740
    on Aug 12, 2026
    More actions

    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.

  3. normanmaurer
    closed this as completedin #17266on Aug 12, 2026
  4. normanmaurer
    added this to the 4.2.18.Final milestone on Aug 12, 2026
  5. normanmaurer commented on Aug 12, 2026

    @normanmaurer
    normanmaurer
    on Aug 12, 2026
    Member
    More actions

    /cc @idelpivnitskiy @bryce-anderson

  6. Gimini-3
    added a commit that references this issue on Aug 12, 2026

    HTTP/2: Prevent reentrant flush on writability change (netty#17266)

    This issue will close once commit 1ec9af2 is merged into the '4.2' branch.
    1ec9af2
  7. normanmaurer
    added 2 commits that reference this issue on Aug 12, 2026

    Auto-port 4.1: HTTP/2: Prevent reentrant flush on writability change (#…

    This issue will close once commit 48c8075 is merged into the '4.2' branch.
    48c8075

    Auto-port 5.0: HTTP/2: Prevent reentrant flush on writability change (#…

    This issue will close once commit 03447d5 is merged into the '4.2' branch.
    03447d5
  8. bryce-anderson
    added 3 commits that reference this issue on Aug 12, 2026

    HTTP/2: Drain queued frames stranded by a writability change during f…

    ed98441

    HTTP/2: Drain queued frames stranded by a writability change during f…

    3296cd7

    HTTP/2: Drain queued frames stranded by a writability change during f…

    7b05104
  9. bryce-anderson commented on Aug 13, 2026

    @bryce-anderson
    bryce-anderson
    on Aug 13, 2026
    Contributor
    More actions

    @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.

  10. Zohaibcode740 commented on Aug 13, 2026

    @Zohaibcode740
    Zohaibcode740
    on Aug 13, 2026
    More actions

    @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.

  11. normanmaurer
    added 3 commits that reference this issue on Aug 13, 2026

    HTTP/2: Drain queued frames stranded by a writability change during f…

    67896b2

    Auto-port 4.1: HTTP/2: Drain queued frames stranded by a writability …

    29e3d85

    HTTP/2: Drain queued frames stranded by a writability change during f…

    50ebe4c
  12. bryce-anderson commented on Aug 13, 2026

    @bryce-anderson
    bryce-anderson
    on Aug 13, 2026
    Contributor
    More actions

    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
  13. bryce-anderson commented on Aug 17, 2026

    @bryce-anderson
    bryce-anderson
    on Aug 17, 2026
    Contributor
    More actions

    Ping @Zohaibcode740 , @vitolibrarius for the full stack trace with line numbers.

    Reacted by Syed Zohaib Ali
  14. lltopk
    added 2 commits that reference this issue on Oct 24, 2026

    Auto-port 4.1: HTTP/2: Prevent reentrant flush on writability change (n…

    This issue will close once commit 67c4594 is merged into the '4.2' branch.
    67c4594

    Auto-port 4.1: HTTP/2: Drain queued frames stranded by a writability …

    This issue will close once commit f26202e is merged into the '4.2' branch.
    f26202e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.2.18.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.