Skip to content

HTTP/2: Drain queued frames stranded by a writability change during flush - #17279

Merged
normanmaurer merged 1 commit into
netty:4.2from
bryce-anderson:bl_anderson/h2-flush-stall
Aug 13, 2026
Merged

normanmaurer merged 1 commit into
netty:4.2from
bryce-anderson:bl_anderson/h2-flush-stall

Conversation

@bryce-anderson

@bryce-anderson bryce-anderson commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Motivation:

The inFlush guard added in #17266 (fixing livelock #17256) drops a flush that
re-enters via a synchronous writability change. But when writePendingBytes()
leaves frames queued and the following ctx.flush() drains the transport and
flips the channel writable mid-flush, that dropped flush was the only signal to
write the rest — so large writes (e.g. a multi-MiB gRPC body) hang.

Modification:

  • Gate the writability-driven flush: channelWritabilityChanged only flushes when
    the remote flow controller still has frames queued, so a writability toggle
    with nothing to write (e.g. SslHandler during setup) can't drive the
    flush -> writability -> flush livelock (Netty HTTP/2 client livelock — reentrant flush during pipeline setup #17256).
  • flush() re-runs while a flush was requested reentrantly while it was running,
    honoring it regardless of writability; the inFlush guard turns that reentrancy
    into iteration rather than recursion.

Result:

Large HTTP/2 writes no longer stall on a mid-flush writability flip, and #17256
stays fixed.

…lush

Motivation:

The `inFlush` guard added in netty#17266 (fixing livelock netty#17256) drops a flush that
re-enters via a synchronous writability change. But when writePendingBytes()
leaves frames queued and the following ctx.flush() drains the transport and
flips the channel writable mid-flush, that dropped flush was the only signal to
write the rest — so large writes (e.g. a multi-MiB gRPC body) hang.

Modification:

- Gate the writability-driven flush: channelWritabilityChanged only flushes when
  the remote flow controller still has frames queued, so a writability toggle
  with nothing to write (e.g. SslHandler during setup) can't drive the
  flush -> writability -> flush livelock (netty#17256).
- flush() re-runs while a flush was requested reentrantly while it was running,
  honoring it regardless of writability; the inFlush guard turns that reentrancy
  into iteration rather than recursion.

Result:

Large HTTP/2 writes no longer stall on a mid-flush writability flip, and netty#17256
stays fixed.
@testlens-app

testlens-app Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 7b05104
▶️ Tests: 448046 executed
⚪️ Checks: 22/22 completed


Learn more about TestLens at testlens.app.

@bryce-anderson

bryce-anderson commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor Author

So, I think this will fix the stalls, but I'm still curious about how #17256 happens. The stack trace as described does look re-entrant, but if it were truly spinning like that it would stack-overflow immediately and that would be rather obvious. It could also be that something else was spinning synchronously (maybe a SslHandler loop just as a wild guess) forever and the trail of the trace is happenstance.

@normanmaurer normanmaurer added this to the 4.2.18.Final milestone Aug 13, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Aug 13, 2026
@normanmaurer

Copy link
Copy Markdown
Member

@bryce-anderson I think we might just have "spinned" for some time and not long enough to get a stack overflow.

@normanmaurer
normanmaurer merged commit 67896b2 into netty:4.2 Aug 13, 2026
23 checks passed
@netty-project-bot

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 5.0.

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #17280

@normanmaurer

Copy link
Copy Markdown
Member

PR for 5.0 #17281

normanmaurer added a commit that referenced this pull request Aug 13, 2026
…change during flush (#17280)

Auto-port of #17279 to 4.1
Cherry-picked commit: 67896b2

---
Motivation:

The `inFlush` guard added in #17266 (fixing livelock #17256) drops a
flush that
re-enters via a synchronous writability change. But when
writePendingBytes()
leaves frames queued and the following ctx.flush() drains the transport
and
flips the channel writable mid-flush, that dropped flush was the only
signal to
write the rest — so large writes (e.g. a multi-MiB gRPC body) hang.

Modification:

- Gate the writability-driven flush: channelWritabilityChanged only
flushes when
the remote flow controller still has frames queued, so a writability
toggle
  with nothing to write (e.g. SslHandler during setup) can't drive the
  flush -> writability -> flush livelock (#17256).
- flush() re-runs while a flush was requested reentrantly while it was
running,
honoring it regardless of writability; the inFlush guard turns that
reentrancy
  into iteration rather than recursion.

Result:

Large HTTP/2 writes no longer stall on a mid-flush writability flip, and
#17256
stays fixed.

---------

Co-authored-by: Bryce Anderson <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Aug 13, 2026
…lush (#17279) (#17281)

Motivation:

The `inFlush` guard added in #17266 (fixing livelock #17256) drops a
flush that
re-enters via a synchronous writability change. But when
writePendingBytes()
leaves frames queued and the following ctx.flush() drains the transport
and
flips the channel writable mid-flush, that dropped flush was the only
signal to
write the rest — so large writes (e.g. a multi-MiB gRPC body) hang.

Modification:

- Gate the writability-driven flush: channelWritabilityChanged only
flushes when
the remote flow controller still has frames queued, so a writability
toggle
  with nothing to write (e.g. SslHandler during setup) can't drive the
  flush -> writability -> flush livelock (#17256).
- flush() re-runs while a flush was requested reentrantly while it was
running,
honoring it regardless of writability; the inFlush guard turns that
reentrancy
  into iteration rather than recursion.

Result:

Large HTTP/2 writes no longer stall on a mid-flush writability flip, and

Co-authored-by: Bryce Anderson <[email protected]>
@bryce-anderson
bryce-anderson deleted the bl_anderson/h2-flush-stall branch August 13, 2026 14:59
@chrisvest chrisvest removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Aug 13, 2026
normanmaurer added a commit that referenced this pull request Sep 16, 2026
Motivation:

The reentrancy fix landed in #17279 already covers this case, since
the inFlush/flushAgain guard in flush() now spans the whole call
rather than just individual iterations.

Modifications:

- adds the regression test from #17276 to lock in that behavior.

Result:

Better test coverage
normanmaurer added a commit that referenced this pull request Sep 17, 2026
…sh() (#17504)

Auto-port of #17497 to 5.0
Cherry-picked commit: 9b96442

---
Motivation:

The reentrancy fix landed in #17279 already covers this case, since
the inFlush/flushAgain guard in flush() now spans the whole call
rather than just individual iterations.

Modifications:

- adds the regression test from #17276 to lock in that behavior.

Result:

Better test coverage

---------

Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Sep 17, 2026
…sh() (#17505)

Auto-port of #17497 to 4.1
Cherry-picked commit: 9b96442

---
Motivation:

The reentrancy fix landed in #17279 already covers this case, since
the inFlush/flushAgain guard in flush() now spans the whole call
rather than just individual iterations.

Modifications:

- adds the regression test from #17276 to lock in that behavior.

Result:

Better test coverage

Co-authored-by: Norman Maurer <[email protected]>
ravi-signal pushed a commit to signalapp/Signal-Server that referenced this pull request Sep 23, 2026
The latter is a regression test for hangs (fixed in Netty 4.2.18,
netty/netty#17279) and response truncation.
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…change during flush (netty#17280)

Auto-port of netty#17279 to 4.1
Cherry-picked commit: 67896b2

---
Motivation:

The `inFlush` guard added in netty#17266 (fixing livelock netty#17256) drops a
flush that
re-enters via a synchronous writability change. But when
writePendingBytes()
leaves frames queued and the following ctx.flush() drains the transport
and
flips the channel writable mid-flush, that dropped flush was the only
signal to
write the rest — so large writes (e.g. a multi-MiB gRPC body) hang.

Modification:

- Gate the writability-driven flush: channelWritabilityChanged only
flushes when
the remote flow controller still has frames queued, so a writability
toggle
  with nothing to write (e.g. SslHandler during setup) can't drive the
  flush -> writability -> flush livelock (netty#17256).
- flush() re-runs while a flush was requested reentrantly while it was
running,
honoring it regardless of writability; the inFlush guard turns that
reentrancy
  into iteration rather than recursion.

Result:

Large HTTP/2 writes no longer stall on a mid-flush writability flip, and
netty#17256
stays fixed.

---------

Co-authored-by: Bryce Anderson <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…sh() (netty#17505)

Auto-port of netty#17497 to 4.1
Cherry-picked commit: 9b96442

---
Motivation:

The reentrancy fix landed in netty#17279 already covers this case, since
the inFlush/flushAgain guard in flush() now spans the whole call
rather than just individual iterations.

Modifications:

- adds the regression test from netty#17276 to lock in that behavior.

Result:

Better test coverage

Co-authored-by: Norman Maurer <[email protected]>
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.

4 participants