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 — HTTP/2: Prevent reentrant flush on writability change by arnabnandy7 · Pull Request #17266 · netty/netty

Conversation

@arnabnandy7

@arnabnandy7 arnabnandy7 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Motivation:

An HTTP/2 connection can enter a livelock when a flush synchronously triggers a channel writability change. channelWritabilityChanged then re-enters Http2ConnectionHandler.flush() while the original flush is still in progress, causing the event-loop thread to spin indefinitely.

Modification:

Track when Http2ConnectionHandler is performing a flush and prevent channelWritabilityChanged from initiating a nested flush during that operation.

Add a regression test that simulates a synchronous writability change during ChannelHandlerContext.flush() and verifies that the flush is not re-entered.

Result:

Fixes #17256.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@arnabnandy7
HTTP/2: Prevent reentrant flush on writability change
d7a0cd4
Signed-off-by: Arnab Nandy <[email protected]>
normanmaurer
normanmaurer approved these changes Aug 11, 2026
View reviewed changes
@testlens-app

testlens-app Bot commented Aug 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

🚨 TestLens detected 1 failed test 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Test Summary

Build PR / macos-x86_64-java11-boringssl build > Netty/Transport/Native/KQueue

Test Runs Flakiness
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendHeapByteBuf(TestInfo) ✅ ❌ 4% 🟡
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendWithoutBind(TestInfo) ❌ ✅ 3% 🟡

🏷️ Commit: d7a0cd4
▶️ Tests: 812 executed
🟡 Checks: 22/24 completed

Test Failures

KQueueDatagramUnicastIPv6MappedTest > testSimpleSendHeapByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-x86_64-java11-boringssl build)
org.opentest4j.AssertionFailedError
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend0(DatagramUnicastTest.java:360)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend(DatagramUnicastTest.java:192)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendHeapByteBuf(DatagramUnicastTest.java:103)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$2.run(DatagramUnicastTest.java:97)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$2.run(DatagramUnicastTest.java:94)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendHeapByteBuf(DatagramUnicastTest.java:94)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

Muted Tests

Note

Checks are currently running using the configuration below.

Select tests to mute in this pull request:

🔲 KQueueDatagramUnicastIPv6MappedTest > testSimpleSendHeapByteBuf(TestInfo)
🔲 KQueueDatagramUnicastIPv6MappedTest > testSimpleSendWithoutBind(TestInfo)

Reuse successful test results:

🔲 ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

☑️ Rerun jobs


Learn more about TestLens at testlens.app.

arnabnandy7 reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@arnabnandy7

arnabnandy7 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Please re-run this failed test case.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer normanmaurer added this to the 4.2.18.Final milestone Aug 12, 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 12, 2026
@normanmaurer
normanmaurer merged commit 1ec9af2 into netty:4.2 Aug 12, 2026
37 of 39 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot

netty-project-bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #17267

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot netty-project-bot mentioned this pull request Aug 12, 2026
Auto-port 5.0: HTTP/2: Prevent reentrant flush on writability change #17267
Merged
@github-actions github-actions Bot removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Aug 12, 2026
@netty-project-bot

netty-project-bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #17268

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot netty-project-bot mentioned this pull request Aug 12, 2026
Auto-port 4.1: HTTP/2: Prevent reentrant flush on writability change #17268
Merged
@github-actions github-actions Bot removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Aug 12, 2026
normanmaurer pushed a commit that referenced this pull request Aug 12, 2026
@netty-project-bot @arnabnandy7
Auto-port 4.1: HTTP/2: Prevent reentrant flush on writability change (#…
48c8075
…17268)

Auto-port of #17266 to 4.1
Cherry-picked commit: 1ec9af2

---
Motivation:

An HTTP/2 connection can enter a livelock when a flush synchronously
triggers a channel writability change. `channelWritabilityChanged` then
re-enters `Http2ConnectionHandler.flush()` while the original flush is
still in progress, causing the event-loop thread to spin indefinitely.

Modification:

Track when `Http2ConnectionHandler` is performing a flush and prevent
`channelWritabilityChanged` from initiating a nested flush during that
operation.

Add a regression test that simulates a synchronous writability change
during `ChannelHandlerContext.flush()` and verifies that the flush is
not re-entered.

Result:

Fixes #17256.

Signed-off-by: Arnab Nandy <[email protected]>
Co-authored-by: Arnab Nandy <[email protected]>
normanmaurer pushed a commit that referenced this pull request Aug 12, 2026
@netty-project-bot @arnabnandy7
Auto-port 5.0: HTTP/2: Prevent reentrant flush on writability change (#…
03447d5
…17267)

Auto-port of #17266 to 5.0
Cherry-picked commit: 1ec9af2

---
Motivation:

An HTTP/2 connection can enter a livelock when a flush synchronously
triggers a channel writability change. `channelWritabilityChanged` then
re-enters `Http2ConnectionHandler.flush()` while the original flush is
still in progress, causing the event-loop thread to spin indefinitely.

Modification:

Track when `Http2ConnectionHandler` is performing a flush and prevent
`channelWritabilityChanged` from initiating a nested flush during that
operation.

Add a regression test that simulates a synchronous writability change
during `ChannelHandlerContext.flush()` and verifies that the flush is
not re-entered.

Result:

Fixes #17256.

Signed-off-by: Arnab Nandy <[email protected]>
Co-authored-by: Arnab Nandy <[email protected]>
bryce-anderson added a commit to bryce-anderson/netty that referenced this pull request Aug 12, 2026
@bryce-anderson
HTTP/2: Drain queued frames stranded by a writability change during f…
ed98441
…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:

- After the in-progress flush, re-run writePendingBytes()/ctx.flush() while a
  reentrant flush was requested, the channel is writable, and the flow
  controller still has queued frames. Gating on queued data drains stranded
  writes without re-livelocking on empty toggles (the netty#17256 SslHandler/preface
  path has nothing queued).
- Add DefaultHttp2RemoteFlowController.hasPendingBytes() (O(1), no API change)
  for that check.

Result:

Large HTTP/2 writes no longer stall on a mid-flush writability flip, and netty#17256
stays fixed.
@vitolibrarius vitolibrarius mentioned this pull request Aug 12, 2026
Netty HTTP/2 client livelock during close() — reentrant flush via channelWritabilityChanged, second variant not covered by #17266 #17276
Closed
bryce-anderson added a commit to bryce-anderson/netty that referenced this pull request Aug 12, 2026
@bryce-anderson
HTTP/2: Drain queued frames stranded by a writability change during f…
3296cd7
…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.
bryce-anderson added a commit to bryce-anderson/netty that referenced this pull request Aug 12, 2026
@bryce-anderson
HTTP/2: Drain queued frames stranded by a writability change during f…
7b05104
…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.
@bryce-anderson bryce-anderson mentioned this pull request Aug 12, 2026
HTTP/2: Drain queued frames stranded by a writability change during flush #17279
Merged
@bryce-anderson

bryce-anderson commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

I think this resulted in some stalls when writing large files. I've posted a PR to address it in #17279.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer

normanmaurer commented Aug 13, 2026

Copy link
Copy Markdown
Member

@bryce-anderson thanks !

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer pushed a commit that referenced this pull request Aug 13, 2026
@bryce-anderson
HTTP/2: Drain queued frames stranded by a writability change during f…
67896b2
…lush (#17279)

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.
@netty-project-bot netty-project-bot mentioned this pull request Aug 13, 2026
Auto-port 4.1: HTTP/2: Drain queued frames stranded by a writability change during flush #17280
Merged
@normanmaurer normanmaurer mentioned this pull request Aug 13, 2026
HTTP/2: Drain queued frames stranded by a writability change during flush (#17279) #17281
Merged
normanmaurer added a commit that referenced this pull request Aug 13, 2026
@netty-project-bot @bryce-anderson @normanmaurer
Auto-port 4.1: HTTP/2: Drain queued frames stranded by a writability …
29e3d85
…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
@normanmaurer @bryce-anderson
HTTP/2: Drain queued frames stranded by a writability change during f…
50ebe4c
…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]>
@lhotari lhotari mentioned this pull request Sep 10, 2026
[fix][sec] Upgrade Netty to 4.2.18 to address several CVEs and bugs apache/pulsar#26514
Merged
2 of 11 tasks
@fudianchn fudianchn mentioned this pull request Sep 12, 2026
Guard ChunkedWriteHandler.doFlush() against re-entrant invocation from user code #17438
Merged
normanmaurer pushed a commit that referenced this pull request Sep 16, 2026
@fudianchn
Guard ChunkedWriteHandler.doFlush() against re-entrant invocation fro…
3061561
…m user code (#17438)

## Motivation

`ChunkedWriteHandler.doFlush(...)` intermittently fails with
`NoSuchElementException` from `ArrayDeque.remove()` (#14839).

Root cause: `queue.peek()` and the `queue.remove()` calls are separated
by user code. `ChunkedInput.readChunk(...)` and `isEndOfInput()` run
between them, and that user code can synchronously re-enter the handler
— an incidental `flush()`, a `resumeTransfer()`, a writability change,
or a close notification. The nested `doFlush(...)` peeks and consumes
the *same* queue entry:

1. the outer invocation then calls `queue.remove()` on an already-empty
queue → `NoSuchElementException`,
2. both invocations read from the same input — including after the
nested one closed it,
3. the double consumption leaks a chunk buffer (caught by leak detection
in the regression test).

A deterministic reproducer on 4.1.119 matches the stack reported on
4.1.118 frame by frame (`doFlush:287`, `flush:146`).

## Modification

1. Guard `doFlush(...)` against re-entrant invocation: an `inFlush`
flag, cleared in `finally` — same shape as the re-entrancy guard added
to `Http2ConnectionHandler.flush(...)` in #17266.
2. A nested call is remembered (`flushPending`), not dropped: the outer
invocation re-runs the drain loop before returning. A plain `return`
guard would lose a `resumeTransfer(...)` that arrives while the transfer
is about to suspend — the same lost-resume problem the old lock-based
guard addressed with `flushRequired` (#637).
3. Two regression tests in `ChunkedWriteHandlerTest`:
- re-entrant `flush()` from `readChunk(...)`: fails on master with the
reported `NoSuchElementException` and a leak-detection error, passes
with the guard; asserts the input is read exactly twice, closed exactly
once after the last read, both chunks written once in order, and the
promise succeeds,
- `resumeTransfer()` from a suspending `readChunk(...)`: passes on
master (where the nested call does the work but the outer
`NoSuchElementException` is not surfaced to the caller) and on the
guard, fails on a plain-`return` variant of the guard (transfer hangs) —
it pins the no-lost-resume property.

## Result

Fixes #14839.

Signed-off-by: 付典 <[email protected]>
@netty-project-bot netty-project-bot mentioned this pull request Sep 16, 2026
Auto-port 4.1: Guard ChunkedWriteHandler.doFlush() against re-entrant invocation from user code #17501
Merged
@normanmaurer normanmaurer mentioned this pull request Sep 16, 2026
Port: Guard ChunkedWriteHandler.doFlush() against re-entrant invocation from user code (#17438) #17503
Merged
normanmaurer pushed a commit that referenced this pull request Sep 16, 2026
@netty-project-bot @fudianchn
Auto-port 4.1: Guard ChunkedWriteHandler.doFlush() against re-entrant…
2550ea3
… invocation from user code (#17501)

Auto-port of #17438 to 4.1
Cherry-picked commit: 3061561

---
AI disclosure: this change was prepared with AI coding agents, reviewed
and revised line by line by me.

## Motivation

`ChunkedWriteHandler.doFlush(...)` intermittently fails with
`NoSuchElementException` from `ArrayDeque.remove()` (#14839).

Root cause: `queue.peek()` and the `queue.remove()` calls are separated
by user code. `ChunkedInput.readChunk(...)` and `isEndOfInput()` run
between them, and that user code can synchronously re-enter the handler
— an incidental `flush()`, a `resumeTransfer()`, a writability change,
or a close notification. The nested `doFlush(...)` peeks and consumes
the *same* queue entry:

1. the outer invocation then calls `queue.remove()` on an already-empty
queue → `NoSuchElementException`,
2. both invocations read from the same input — including after the
nested one closed it,
3. the double consumption leaks a chunk buffer (caught by leak detection
in the regression test).

A deterministic reproducer on 4.1.119 matches the stack reported on
4.1.118 frame by frame (`doFlush:287`, `flush:146`).

## Modification

1. Guard `doFlush(...)` against re-entrant invocation: an `inFlush`
flag, cleared in `finally` — same shape as the re-entrancy guard added
to `Http2ConnectionHandler.flush(...)` in #17266.
2. A nested call is remembered (`flushPending`), not dropped: the outer
invocation re-runs the drain loop before returning. A plain `return`
guard would lose a `resumeTransfer(...)` that arrives while the transfer
is about to suspend — the same lost-resume problem the old lock-based
guard addressed with `flushRequired` (#637).
3. Two regression tests in `ChunkedWriteHandlerTest`:
- re-entrant `flush()` from `readChunk(...)`: fails on master with the
reported `NoSuchElementException` and a leak-detection error, passes
with the guard; asserts the input is read exactly twice, closed exactly
once after the last read, both chunks written once in order, and the
promise succeeds,
- `resumeTransfer()` from a suspending `readChunk(...)`: passes on
master (where the nested call does the work but the outer
`NoSuchElementException` is not surfaced to the caller) and on the
guard, fails on a plain-`return` variant of the guard (transfer hangs) —
it pins the no-lost-resume property.

## Result

Fixes #14839.

Signed-off-by: 付典 <[email protected]>
Co-authored-by: fudian <[email protected]>
normanmaurer added a commit that referenced this pull request Sep 17, 2026
@normanmaurer @fudianchn
Port: Guard ChunkedWriteHandler.doFlush() against re-entrant invocati…
3ac1c84
…on from user code (#17438) (#17503)

`ChunkedWriteHandler.doFlush(...)` intermittently fails with
`NoSuchElementException` from `ArrayDeque.remove()` (#14839).

Root cause: `queue.peek()` and the `queue.remove()` calls are separated
by user code. `ChunkedInput.readChunk(...)` and `isEndOfInput()` run
between them, and that user code can synchronously re-enter the handler
— an incidental `flush()`, a `resumeTransfer()`, a writability change,
or a close notification. The nested `doFlush(...)` peeks and consumes
the *same* queue entry:

1. the outer invocation then calls `queue.remove()` on an already-empty
queue → `NoSuchElementException`,
2. both invocations read from the same input — including after the
nested one closed it,
3. the double consumption leaks a chunk buffer (caught by leak detection
in the regression test).

A deterministic reproducer on 4.1.119 matches the stack reported on
4.1.118 frame by frame (`doFlush:287`, `flush:146`).

1. Guard `doFlush(...)` against re-entrant invocation: an `inFlush`
flag, cleared in `finally` — same shape as the re-entrancy guard added
to `Http2ConnectionHandler.flush(...)` in #17266.
2. A nested call is remembered (`flushPending`), not dropped: the outer
invocation re-runs the drain loop before returning. A plain `return`
guard would lose a `resumeTransfer(...)` that arrives while the transfer
is about to suspend — the same lost-resume problem the old lock-based
guard addressed with `flushRequired` (#637).
3. Two regression tests in `ChunkedWriteHandlerTest`:
- re-entrant `flush()` from `readChunk(...)`: fails on master with the
reported `NoSuchElementException` and a leak-detection error, passes
with the guard; asserts the input is read exactly twice, closed exactly
once after the last read, both chunks written once in order, and the
promise succeeds,
- `resumeTransfer()` from a suspending `readChunk(...)`: passes on
master (where the nested call does the work but the outer
`NoSuchElementException` is not surfaced to the caller) and on the
guard, fails on a plain-`return` variant of the guard (transfer hangs) —
it pins the no-lost-resume property.

Fixes #14839.

Signed-off-by: 付典 <[email protected]>

Signed-off-by: 付典 <[email protected]>
Co-authored-by: fudian <[email protected]>
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
child5 #17695
Closed
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@netty-project-bot @arnabnandy7 @lltopk
Auto-port 4.1: HTTP/2: Prevent reentrant flush on writability change (n…
67c4594
…etty#17268)

Auto-port of netty#17266 to 4.1
Cherry-picked commit: 1ec9af2

---
Motivation:

An HTTP/2 connection can enter a livelock when a flush synchronously
triggers a channel writability change. `channelWritabilityChanged` then
re-enters `Http2ConnectionHandler.flush()` while the original flush is
still in progress, causing the event-loop thread to spin indefinitely.

Modification:

Track when `Http2ConnectionHandler` is performing a flush and prevent
`channelWritabilityChanged` from initiating a nested flush during that
operation.

Add a regression test that simulates a synchronous writability change
during `ChannelHandlerContext.flush()` and verifies that the flush is
not re-entered.

Result:

Fixes netty#17256.

Signed-off-by: Arnab Nandy <[email protected]>
Co-authored-by: Arnab Nandy <[email protected]>
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@netty-project-bot @bryce-anderson
@normanmaurer @lltopk
Auto-port 4.1: HTTP/2: Drain queued frames stranded by a writability …
f26202e
…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
@netty-project-bot @fudianchn @lltopk
Auto-port 4.1: Guard ChunkedWriteHandler.doFlush() against re-entrant…
e3029a1
… invocation from user code (netty#17501)

Auto-port of netty#17438 to 4.1
Cherry-picked commit: 3061561

---
AI disclosure: this change was prepared with AI coding agents, reviewed
and revised line by line by me.

## Motivation

`ChunkedWriteHandler.doFlush(...)` intermittently fails with
`NoSuchElementException` from `ArrayDeque.remove()` (netty#14839).

Root cause: `queue.peek()` and the `queue.remove()` calls are separated
by user code. `ChunkedInput.readChunk(...)` and `isEndOfInput()` run
between them, and that user code can synchronously re-enter the handler
— an incidental `flush()`, a `resumeTransfer()`, a writability change,
or a close notification. The nested `doFlush(...)` peeks and consumes
the *same* queue entry:

1. the outer invocation then calls `queue.remove()` on an already-empty
queue → `NoSuchElementException`,
2. both invocations read from the same input — including after the
nested one closed it,
3. the double consumption leaks a chunk buffer (caught by leak detection
in the regression test).

A deterministic reproducer on 4.1.119 matches the stack reported on
4.1.118 frame by frame (`doFlush:287`, `flush:146`).

## Modification

1. Guard `doFlush(...)` against re-entrant invocation: an `inFlush`
flag, cleared in `finally` — same shape as the re-entrancy guard added
to `Http2ConnectionHandler.flush(...)` in netty#17266.
2. A nested call is remembered (`flushPending`), not dropped: the outer
invocation re-runs the drain loop before returning. A plain `return`
guard would lose a `resumeTransfer(...)` that arrives while the transfer
is about to suspend — the same lost-resume problem the old lock-based
guard addressed with `flushRequired` (netty#637).
3. Two regression tests in `ChunkedWriteHandlerTest`:
- re-entrant `flush()` from `readChunk(...)`: fails on master with the
reported `NoSuchElementException` and a leak-detection error, passes
with the guard; asserts the input is read exactly twice, closed exactly
once after the last read, both chunks written once in order, and the
promise succeeds,
- `resumeTransfer()` from a suspending `readChunk(...)`: passes on
master (where the nested call does the work but the outer
`NoSuchElementException` is not surfaced to the caller) and on the
guard, fails on a plain-`return` variant of the guard (transfer hangs) —
it pins the no-lost-resume property.

## Result

Fixes netty#14839.

Signed-off-by: 付典 <[email protected]>
Co-authored-by: fudian <[email protected]>
@normanmaurer normanmaurer mentioned this pull request Oct 26, 2026
crisp nova cceda091 #18109
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@normanmaurer normanmaurer normanmaurer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.18.Final

Development

Successfully merging this pull request may close these issues.

Netty HTTP/2 client livelock — reentrant flush during pipeline setup

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@arnabnandy7 @netty-project-bot @bryce-anderson @normanmaurer
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.