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 — Port: Guard ChunkedWriteHandler.doFlush() against re-entrant invocation from user code (#17438) by normanmaurer · Pull Request #17503 · netty/netty

Conversation

@normanmaurer

@normanmaurer normanmaurer commented Sep 16, 2026

Copy link
Copy Markdown
Member

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 HTTP/2: Prevent reentrant flush on writability change #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 (Call ChunkedWriteHandler.flush() once again if tried when locked. #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]

Sorry, something went wrong.

Uh oh!

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

All reactions
@fudianchn @normanmaurer
Guard ChunkedWriteHandler.doFlush() against re-entrant invocation fro…
2fe2757
…m user code (#17438)

`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]>
@normanmaurer normanmaurer mentioned this pull request Sep 16, 2026
Guard ChunkedWriteHandler.doFlush() against re-entrant invocation from user code #17438
Merged
@normanmaurer normanmaurer changed the title Guard ChunkedWriteHandler.doFlush() against re-entrant invocation from user code (#17438) Port: Guard ChunkedWriteHandler.doFlush() against re-entrant invocation from user code (#17438) Sep 16, 2026
@testlens-app

testlens-app Bot commented Sep 16, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

✅ All tests passed ✅

⚠️ TestLens detected flakiness ⚠️

Failed Jobs without Test Failures

❌ Build PR / macos-x86_64-java25-boringssl build

Test Summary

Build PR / linux-x86_64-java25-adaptive build > Netty/Codec/HTTP2

Test Runs Flakiness
Http2ConnectionRoundtripTest > createStreamAfterReceiveGoAwayShouldNotSendGoAway() ❌ ✅ 1% 🟡

Build PR / linux-x86_64-java25-graal build > Netty/Codec/HTTP2

Test Runs Flakiness
Http2ConnectionRoundtripTest > listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConn… ❌ ✅ 1% 🟡

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

Test Runs Flakiness
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendWithoutBind(TestInfo) ❌ 🚫 2% 🟡

🏷️ Commit: 2fe2757
▶️ Tests: 71230 executed
⚪️ Checks: 12/12 completed

Test Failures

Http2ConnectionRoundtripTest > createStreamAfterReceiveGoAwayShouldNotSendGoAway() (Netty/Codec/HTTP2 in Build PR / linux-x86_64-java25-adaptive build | Attempt 1/2)
org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:31)
	at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:183)
	at io.netty.handler.codec.http2.Http2ConnectionRoundtripTest.createStreamAfterReceiveGoAwayShouldNotSendGoAway(Http2ConnectionRoundtripTest.java:888)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:511)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.tryRemoveAndExec(ForkJoinPool.java:1490)
	at java.base/java.util.concurrent.ForkJoinPool.helpJoin(ForkJoinPool.java:2248)
	at java.base/java.util.concurrent.ForkJoinTask.awaitDone(ForkJoinTask.java:499)
	at java.base/java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:666)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:511)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1450)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2019)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
expected actual
true false
Http2ConnectionRoundtripTest > listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection() (Netty/Codec/HTTP2 in Build PR / linux-x86_64-java25-graal build | Attempt 1/2)
org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:31)
	at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:183)
	at io.netty.handler.codec.http2.Http2ConnectionRoundtripTest.listenerIsNotifiedOfGoawayBeforeStreamsAreRemovedFromTheConnection(Http2ConnectionRoundtripTest.java:971)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:511)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.tryRemoveAndExec(ForkJoinPool.java:1490)
	at java.base/java.util.concurrent.ForkJoinPool.helpJoin(ForkJoinPool.java:2248)
	at java.base/java.util.concurrent.ForkJoinTask.awaitDone(ForkJoinTask.java:499)
	at java.base/java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:666)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:511)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1450)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2019)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
expected actual
true false
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendWithoutBind(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-x86_64-java25-boringssl build | Attempt 1/2)
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.testSimpleSendWithoutBind(DatagramUnicastTest.java:184)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$6.run(DatagramUnicastTest.java:178)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$6.run(DatagramUnicastTest.java:175)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendWithoutBind(DatagramUnicastTest.java:175)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)

Learn more about TestLens at testlens.app/docs.

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer
normanmaurer merged commit 3ac1c84 into 5.0 Sep 17, 2026
19 of 23 checks passed

Uh oh!

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

@normanmaurer
normanmaurer deleted the chunked_reentrance5 branch September 17, 2026 10:19
@normanmaurer normanmaurer added this to the 5.0.0.Final milestone Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

5.0.0.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

2 participants

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