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: Fix stream stall when toggling auto-read on a child channel by pandareen · Pull Request #17617 · netty/netty

HTTP/2: Fix stream stall when toggling auto-read on a child channel #17617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
normanmaurer merged 6 commits into netty:4.2 from pandareen:claude/gifted-goodall-aj20ng
Sep 28, 2026

Uh oh!

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

Merged

HTTP/2: Fix stream stall when toggling auto-read on a child channel #17617

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
20f199c
Make Http2StreamChannelConfig#setAutoRead() safe to call from any thread
claude Sep 24, 2026
06105bf
Flush WINDOW_UPDATE written by read() while a read is already pending
claude Sep 25, 2026
31db50f
Merge branch '4.2' into claude/gifted-goodall-aj20ng
normanmaurer Sep 25, 2026
cc41e0e
Also flush WINDOW_UPDATE when the parent's read loop is deferring it
normanmaurer Sep 26, 2026
adbd14a
Don't reorder or drop frames delivered re-entrantly during a child read
claude Sep 26, 2026
c7ed8b6
Merge branch '4.2' into claude/gifted-goodall-aj20ng
normanmaurer Sep 26, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

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

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

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

Diff view
Diff view
Prev Previous commit
Next Next commit
Don't reorder or drop frames delivered re-entrantly during a child read
doBeginRead() can stop early (e.g. auto-read was turned off) while frames
are still queued, and then runs pipeline callbacks and flush() with
readStatus still IN_PROGRESS. If those re-entrantly deliver more frames
(e.g. a flush of a WINDOW_UPDATE synchronously makes the remote peer send
more data, as happens with LocalChannel peers on the same EventLoop):

- fireChildRead() dispatched the new frame directly, ahead of the frames
  that were still queued. With assertions enabled this instead tripped
  the "queue must be empty" assert, so the frame was never released or
  consumed, leaking it and stalling the stream's flow-control window.
- If the re-entrant frames ended the stream while some of them were
  queued, notifyReadComplete() (and doBeginRead()) closed the channel
  unconditionally on readEOS, releasing the queued frames and silently
  truncating the stream.

Queue behind already queued frames instead of dispatching out of order,
and only close on EOS once the inbound queue has been fully drained.

This fixes the stall, truncation and leak seen in
proxyMirroringWritabilityToAutoReadAcrossEventLoopsDoesNotStallStream on
CI, and adds deterministic single-threaded tests for both cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018LPAeqinPd3jpGx9xMYiWr
  • Loading branch information

Uh oh!

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

@claude
claude committed Sep 26, 2026
commit adbd14afb50599c046572d9c5ccf41445f6caa8b

There are no files selected for viewing

35 changes: 25 additions & 10 deletions 35 codec-http2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2StreamChannel.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,11 @@ void fireChildRead(Http2Frame frame) {
assert eventLoop().inEventLoop();
if (!isActive()) {
ReferenceCountUtil.release(frame);
} else if (readStatus != ReadStatus.IDLE) {
// If a read is in progress or has been requested, there cannot be anything in the queue,
// otherwise we would have drained it from the queue and processed it during the read cycle.
assert inboundBuffer == null || inboundBuffer.isEmpty();
} else if (readStatus != ReadStatus.IDLE && isInboundBufferEmpty()) {
// A read is in progress or has been requested and nothing is queued, so dispatch directly. If frames are
// still queued (e.g. this frame was delivered re-entrantly while doBeginRead() is running pipeline
// callbacks after it stopped early) we must queue behind them below to preserve ordering; the read loop
// that is still on the stack will drain them.
final RecvByteBufAllocator.Handle allocHandle = unsafe.recvBufAllocHandle();

unsafe.doRead0(frame, allocHandle);
Expand All @@ -624,6 +625,10 @@ void fireChildRead(Http2Frame frame) {
}
}

private boolean isInboundBufferEmpty() {
return inboundBuffer == null || inboundBuffer.isEmpty();
}

void fireChildReadComplete() {
assert eventLoop().inEventLoop();
assert readStatus != ReadStatus.IDLE || !readCompletePending;
Expand Down Expand Up @@ -892,20 +897,23 @@ private Object pollQueuedMessage() {
void doBeginRead() {
if (readStatus == ReadStatus.IDLE) {
// Don't wait for the user to request a read to notify of channel closure.
if (readEOS && (inboundBuffer == null || inboundBuffer.isEmpty())) {
if (readEOS && isInboundBufferEmpty()) {
// Double check there is nothing left to flush such as a window update frame.
flush();
unsafe.closeForcibly();
closeIfReadEOSAndDrained();
}
} else {
do { // Process messages until there are none left (or the user stopped requesting) and also handle EOS.
Object message = pollQueuedMessage();
if (message == null) {
// Double check there is nothing left to flush such as a window update frame.
flush();
if (readEOS) {
unsafe.closeForcibly();
if (!isInboundBufferEmpty()) {
// The flush re-entrantly delivered more frames which got queued; keep reading if we
// still should.
continue;
}
closeIfReadEOSAndDrained();
break;
}
final RecvByteBufAllocator.Handle allocHandle = recvBufAllocHandle();
Expand Down Expand Up @@ -977,8 +985,15 @@ void notifyReadComplete(RecvByteBufAllocator.Handle allocHandle, boolean forceRe
// channel is not currently reading we need to force a flush at the child channel, because we cannot
// rely upon flush occurring in channelReadComplete on the parent channel.
flush();
if (readEOS) {
unsafe.closeForcibly();
closeIfReadEOSAndDrained();
}

private void closeIfReadEOSAndDrained() {
// Pipeline callbacks and flush() can re-entrantly deliver more frames, including the one that ends the
// stream, and queue them if the user stopped reading. Only close once all of them have been read,
// otherwise the queued frames would be released and the stream silently truncated.
if (readEOS && isInboundBufferEmpty()) {
closeForcibly();
}
}

Expand Down
98 changes: 98 additions & 0 deletions 98 codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,104 @@ public void windowUpdateFlushedWhenReadRequestedWhileReadInProgress() {
assertTrue(flushSniffer.checkFlush(), "WINDOW_UPDATE was written but never flushed");
}

@Test
public void framesDeliveredReentrantlyWhileFramesQueuedAreNotReordered() {
final LastInboundHandler inboundHandler = new LastInboundHandler();
final Http2StreamChannel childChannel = newInboundStream(3, false, inboundHandler);
assertNotNull(inboundHandler.readInbound());
final int streamId = childChannel.stream().id();

// Queue two frames while auto-read is disabled. The first is dispatched immediately as a read was pending.
childChannel.config().setAutoRead(false);
frameInboundWriter.writeInboundData(streamId, bb(1), 0, false);
assertDataFrame(inboundHandler, 1, false);
frameInboundWriter.writeInboundData(streamId, bb(2), 0, false);
frameInboundWriter.writeInboundData(streamId, bb(3), 0, false);
assertNull(inboundHandler.readInbound());

// Stop reading again after the first queued frame, and have a new frame arrive re-entrantly (e.g. because a
// flush synchronously triggered the remote peer to send more) while the read loop is still completing.
final AtomicBoolean armed = new AtomicBoolean(true);
childChannel.pipeline().addFirst(new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ctx.channel().config().setAutoRead(false);
ctx.fireChannelRead(msg);
}

@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
if (armed.getAndSet(false)) {
frameInboundWriter.writeInboundData(streamId, bb(4), 0, false);
}
ctx.fireChannelReadComplete();
}
});
childChannel.config().setAutoRead(true);
assertDataFrame(inboundHandler, 2, false);
assertNull(inboundHandler.readInbound());

// The re-entrant frame must be delivered after the frame that was already queued.
childChannel.read();
assertDataFrame(inboundHandler, 3, false);
childChannel.read();
assertDataFrame(inboundHandler, 4, false);
assertNull(inboundHandler.readInbound());
}

@Test
public void endOfStreamDeliveredReentrantlyDoesNotDropQueuedFrames() {
final LastInboundHandler inboundHandler = new LastInboundHandler();
final Http2StreamChannel childChannel = newInboundStream(3, false, inboundHandler);
assertNotNull(inboundHandler.readInbound());
final int streamId = childChannel.stream().id();
// Half-close our side so that receiving END_STREAM fully closes the stream.
assertTrue(childChannel.writeAndFlush(
new DefaultHttp2HeadersFrame(new DefaultHttp2Headers(), true)).isSuccess());

childChannel.config().setAutoRead(false);
frameInboundWriter.writeInboundData(streamId, bb(1), 0, false);
assertDataFrame(inboundHandler, 1, false);
frameInboundWriter.writeInboundData(streamId, bb(2), 0, false);
assertNull(inboundHandler.readInbound());

// While the read loop completes, stop reading and have the rest of the stream (including END_STREAM)
// arrive re-entrantly. The last frame gets queued and the stream is closed at the HTTP/2 level.
final AtomicBoolean armed = new AtomicBoolean(true);
childChannel.pipeline().addFirst(new ChannelInboundHandlerAdapter() {
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
if (armed.getAndSet(false)) {
ctx.channel().config().setAutoRead(false);
frameInboundWriter.writeInboundData(streamId, bb(3), 0, false);
frameInboundWriter.writeInboundData(streamId, bb(4), 0, true);
}
ctx.fireChannelReadComplete();
}
});
childChannel.config().setAutoRead(true);
assertDataFrame(inboundHandler, 2, false);
assertDataFrame(inboundHandler, 3, false);
assertNull(inboundHandler.readInbound());

// The queued END_STREAM frame must not be dropped by closing the channel early.
assertTrue(childChannel.isActive());
childChannel.read();
assertDataFrame(inboundHandler, 4, true);
assertFalse(childChannel.isActive());
}

private static void assertDataFrame(LastInboundHandler inboundHandler, int expectedBytes, boolean endStream) {
Http2DataFrame frame = inboundHandler.readInbound();
assertNotNull(frame, "expected a DATA frame with " + expectedBytes + " bytes");
try {
assertEquals(expectedBytes, frame.content().readableBytes());
assertEquals(endStream, frame.isEndStream());
} finally {
frame.release();
}
}

@ParameterizedTest(name = "{displayName} [{index}] value={0}")
@MethodSource("userEvents")
public void userEventsThatPropagatedToChildChannels(Object userEvent) {
Expand Down
Loading
Oops, something went wrong.

Uh oh!

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

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.