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

Conversation

@pandareen

@pandareen pandareen commented Sep 24, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Motivation:

When setAutoRead() is called on an Http2StreamChannel from a different EventLoop than the one the channel is registered to (e.g., a proxy mirroring writability state between streams on different connections), a race condition can occur. This leaves the stream stalled indefinitely because the auto-read state change may be reordered against or race with read-processing on the stream channel's own EventLoop, preventing the channel from resuming reads and sending flow-control WINDOW_UPDATE frames.

This issue is described in #17600.

Modification:

Modified AbstractHttp2StreamChannel.Http2StreamChannelConfig.setAutoRead() to ensure the auto-read state change is always applied on the channel's own EventLoop, similar to how AUTO_STREAM_FLOW_CONTROL is handled. The method now:

  1. Checks if the channel is registered and if the current thread is on the channel's EventLoop
  2. If so, applies the change immediately via setAutoRead0()
  3. If not, schedules the change to run on the channel's EventLoop via execute()

This ensures thread-safe, EventLoop-confined updates to the auto-read state, preventing races with concurrent read-processing.

Added a comprehensive test crossThreadSetAutoReadResumesStalledStream() that reproduces the issue: it disables auto-read before data arrives (causing the stream to stall once the 64KiB flow-control window is exhausted), then re-enables auto-read from a foreign EventLoop. The test verifies that the stream resumes and delivers the complete response body.

Result:

Fixes #17600. Http2StreamChannel can now safely have its auto-read state toggled from any thread without risking a stalled stream. The fix maintains EventLoop-confinement for all state changes while allowing cross-thread calls to proceed safely.

Sorry, something went wrong.

Uh oh!

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

All reactions
@claude
Make Http2StreamChannelConfig#setAutoRead() safe to call from any thread
20f199c
Http2StreamChannel instances are pinned to their parent Http2 connection's
EventLoop. Code that mirrors the writability of one stream onto the
auto-read state of another (e.g. an HTTP/2-to-HTTP/2 proxy backpressuring
one stream based on another) may need to toggle auto-read on a channel
that belongs to a different Http2 connection, and hence a different
EventLoop, than the calling thread.

Apply the change on the channel's own EventLoop, mirroring the existing
AUTO_STREAM_FLOW_CONTROL handling in the same class, so callers no longer
need to hand-roll an inEventLoop() check themselves.

Fixes netty#17600.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018LPAeqinPd3jpGx9xMYiWr
@normanmaurer

normanmaurer commented Sep 24, 2026

Copy link
Copy Markdown
Member

I don't think this is the right fix... It's just a workaround

All reactions

Sorry, something went wrong.

Uh oh!

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

@claude
Flush WINDOW_UPDATE written by read() while a read is already pending
06105bf
Http2ChannelUnsafe.beginRead() always returns consumed bytes to the flow
controller, which may write a WINDOW_UPDATE to the parent without flushing
it. Only the IDLE branch flushed (via doBeginRead()); when read() was
called while readStatus was IN_PROGRESS or REQUESTED the WINDOW_UPDATE was
left in the parent's outbound buffer. Once the remote peer exhausted its
flow-control window nothing else flushed the connection and the stream
stalled at 65535 bytes.

This is easy to hit by toggling auto-read (e.g. mirroring the writability
of another stream), since each setAutoRead(true) issues a read() at an
arbitrary point. Doing so from another EventLoop only makes it more
likely, so the previous setAutoRead() EventLoop-dispatch workaround is
reverted, along with the transport test that passed with or without it.

Fixes netty#17600.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018LPAeqinPd3jpGx9xMYiWr
@pandareen

pandareen commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

You're right, thanks for pushing back. The first version only moved setAutoRead() onto the EventLoop, and it didn't address the actual bug. I've replaced it.

Root cause

Http2ChannelUnsafe.beginRead() always calls updateLocalWindowIfNeeded(), which returns the consumed bytes to the flow controller. That can write a connection- and stream-level WINDOW_UPDATE to the parent context without flushing it.

Only the IDLE branch flushed afterwards, via doBeginRead(). If read() is called while readStatus is IN_PROGRESS or REQUESTED, the WINDOW_UPDATE stays in the parent's outbound buffer. Once the remote peer uses up its flow-control window, nothing else flushes the connection, so the stream stalls at 65535 bytes, which is what the issue reports.

Why toggling auto-read triggers it

Each setAutoRead(false) → setAutoRead(true) flip issues a read() at an arbitrary point. That leaves the child in REQUESTED / IN_PROGRESS with frames delivered but their bytes not yet returned.

Doing the flip from another EventLoop only makes this more likely. It isn't a threading bug: it reproduces on a single thread.

Changes

  • beginRead() now flushes when it wrote a window update and no read loop ran. flush() still defers to the parent's read-complete flush when the parent is mid-read.
  • Reverted the setAutoRead() EventLoop-dispatch change and removed the transport test. That test passed with or without either change, so it didn't prove anything.
  • Added windowUpdateFlushedWhenReadRequestedWhileReadInProgress to Http2MultiplexTest. It's deterministic and single-threaded:
    • Without the fix: fails, because the WINDOW_UPDATEs are written but never flushed.
    • With the fix: passes for both Http2MultiplexCodec and Http2MultiplexHandler.
All reactions

Sorry, something went wrong.

Uh oh!

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

@pandareen pandareen changed the title Make Http2StreamChannelConfig#setAutoRead() safe to call from any thread HTTP/2: Fix stream stall when toggling auto-read on a child channel Sep 25, 2026
@normanmaurer

normanmaurer commented Sep 25, 2026

Copy link
Copy Markdown
Member

Closing this one... will work on a proper fix.

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer normanmaurer closed this Sep 25, 2026
@normanmaurer normanmaurer reopened this Sep 25, 2026
@normanmaurer
Merge branch '4.2' into claude/gifted-goodall-aj20ng
31db50f
@normanmaurer

normanmaurer commented Sep 25, 2026

Copy link
Copy Markdown
Member

@pandareen did you sign our ICLA ?

All reactions

Sorry, something went wrong.

Uh oh!

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

@pandareen

pandareen commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

@pandareen did you sign our ICLA ?

yes

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer

normanmaurer commented Sep 25, 2026

Copy link
Copy Markdown
Member

This fix looks good and makes sense... waiting for the CI.

pandareen reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

normanmaurer and others added 2 commits September 26, 2026 02:39
@normanmaurer @claude
Also flush WINDOW_UPDATE when the parent's read loop is deferring it
cc41e0e
The previous fix flushes the WINDOW_UPDATE written by beginRead() when a
read is already in progress, but Http2ChannelUnsafe#flush() itself is a
no-op while isParentReadInProgress() is true (Http2MultiplexHandler
batches all children's flushes into one ctx.flush() at the end of its
read loop instead). That batched flush only runs at all if some channel
registered via maybeAddChannelToReadCompletePendingQueue(), which this
branch didn't do. So a cross-thread setAutoRead(true) landing here as
the only activity in the parent's read loop left the queue empty, the
end-of-loop flush skipped, and the WINDOW_UPDATE stuck forever.

Register into that same pending queue while the parent is reading, so
its end-of-read-loop flush covers this case too.

Also adds an end-to-end test mirroring the exact proxy pattern from the
issue (writability of one stream driving setAutoRead() on another,
across two separate EventLoops), and a torture test that hammers
setAutoRead() from a background thread while a large payload streams
in -- this is what actually surfaces the gap above; the existing
gentler toggling in the previous test never lands in the exact timing
window that triggers it.

Co-Authored-By: Claude <[email protected]>
@claude
Don't reorder or drop frames delivered re-entrantly during a child read
adbd14a
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
@pandareen

pandareen commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

SingleThreadEventExecutorTest.testSuspendDoesNotRaceWithCancelledScheduledTask failure is unrelated to this change: it's in netty-common, which this PR doesn't touch (only codec-http2). The test was added by #17601 and is timing-dependent. It has failed twice on this PR's CI runs (Java 21 Graal, Java 25), so it may be worth a look separately.

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.19.Final milestone Sep 26, 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 Sep 26, 2026
@normanmaurer

normanmaurer commented Sep 26, 2026

Copy link
Copy Markdown
Member

@pandareen I did add some more code as the fix was not 100 % correct before. Now it should be

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer
Merge branch '4.2' into claude/gifted-goodall-aj20ng
c7ed8b6
@testlens-app

testlens-app Bot commented Sep 26, 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% 🟡

🏷️ Commit: c7ed8b6
▶️ Tests: 424558 executed
⚪️ Checks: 25/25 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:368)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend(DatagramUnicastTest.java:194)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendHeapByteBuf(DatagramUnicastTest.java:106)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$2.run(DatagramUnicastTest.java:99)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$2.run(DatagramUnicastTest.java:96)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendHeapByteBuf(DatagramUnicastTest.java:96)
	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)

Rerun Controls

Select tests to mute in this pull request:

  • KQueueDatagramUnicastIPv6MappedTest > testSimpleSendHeapByteBuf(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/docs.

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer
normanmaurer merged commit ee269f5 into netty:4.2 Sep 28, 2026
25 of 26 checks passed

Uh oh!

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

@netty-project-bot netty-project-bot mentioned this pull request Sep 28, 2026
Auto-port 4.1: HTTP/2: Fix stream stall when toggling auto-read on a child channel #17646
Merged
@netty-project-bot

netty-project-bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #17646

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Sep 28, 2026
@netty-project-bot

netty-project-bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer

normanmaurer commented Sep 28, 2026

Copy link
Copy Markdown
Member

Port for 5.0: #17650

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer normanmaurer removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Sep 28, 2026
normanmaurer added a commit that referenced this pull request Sep 28, 2026
@netty-project-bot @pandareen @normanmaurer
Auto-port 4.1: HTTP/2: Fix stream stall when toggling auto-read on a …
c04f8e9
…child channel (#17646)

Auto-port of #17617 to 4.1
Cherry-picked commit: ee269f5

---
Motivation:

When `setAutoRead()` is called on an `Http2StreamChannel` from a
different EventLoop than the one the channel is registered to (e.g., a
proxy mirroring writability state between streams on different
connections), a race condition can occur. This leaves the stream stalled
indefinitely because the auto-read state change may be reordered against
or race with read-processing on the stream channel's own EventLoop,
preventing the channel from resuming reads and sending flow-control
WINDOW_UPDATE frames.

This issue is described in #17600.

Modification:

Modified
`AbstractHttp2StreamChannel.Http2StreamChannelConfig.setAutoRead()` to
ensure the auto-read state change is always applied on the channel's own
EventLoop, similar to how `AUTO_STREAM_FLOW_CONTROL` is handled. The
method now:

1. Checks if the channel is registered and if the current thread is on
the channel's EventLoop
2. If so, applies the change immediately via `setAutoRead0()`
3. If not, schedules the change to run on the channel's EventLoop via
`execute()`

This ensures thread-safe, EventLoop-confined updates to the auto-read
state, preventing races with concurrent read-processing.

Added a comprehensive test
`crossThreadSetAutoReadResumesStalledStream()` that reproduces the
issue: it disables auto-read before data arrives (causing the stream to
stall once the 64KiB flow-control window is exhausted), then re-enables
auto-read from a foreign EventLoop. The test verifies that the stream
resumes and delivers the complete response body.

Result:

Fixes #17600. Http2StreamChannel can now safely have its auto-read state
toggled from any thread without risking a stalled stream. The fix
maintains EventLoop-confinement for all state changes while allowing
cross-thread calls to proceed safely.

---------

Co-authored-by: pandareen <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Sep 28, 2026
@normanmaurer @pandareen
Port: HTTP/2: Fix stream stall when toggling auto-read on a child cha…
9af412f
…nnel (#17617) (#17650)

Motivation:

When `setAutoRead()` is called on an `Http2StreamChannel` from a
different EventLoop than the one the channel is registered to (e.g., a
proxy mirroring writability state between streams on different
connections) we can end up not flushing the window update frame.

Modification:

- Ensure the window update frame is always flushed
- Add unit tests

Result:

Fixes #17600.

---------

Co-authored-by: Norman Maurer <[email protected]>

---------

Co-authored-by: pandareen <[email protected]>
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
Use LocalIoHandler instead of DefaultEventLoop for LocalChannel tests in codec-http2 #17697
Merged
normanmaurer added a commit that referenced this pull request Oct 1, 2026
@normanmaurer
Use LocalIoHandler instead of DefaultEventLoop for LocalChannel tests…
d3817ad
… in codec-http2 (#17697)

Motivation:

Http2MultiplexTransportTest failed on CI in the LeakPresenceExtension
afterAll check ("Possible memory leak detected for resource scope")
although every test in the class passed. The check waits up to 5 seconds
for resources to be released, so something stayed open for good rather
than just shutting down slowly.

Several tests run LocalChannel / LocalServerChannel on a
DefaultEventLoop
and then call shutdownGracefully() without waiting. Unlike
LocalIoHandler (and NioIoHandler for the other tests in the class),
DefaultEventLoop does not close the channels registered with it when it
shuts down. A server-side child channel is therefore only closed if the
peer-close task still runs before the loop terminates. If it does not,
the channel and whatever it still holds (for example the large wrapped
payloads written by the auto-read tests added in #17617) is never
released, which the leak presence detector reports.

Modification:

- Use `new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory())`
instead of `new DefaultEventLoop()` in the LocalChannel based tests of
Http2MultiplexTransportTest, Http2MultiplexCodecBuilderTest and
Http2StreamChannelBootstrapTest. LocalIoHandler closes all registered
channels when the group shuts down. A single thread is kept so server
and client still share one event loop as before.

Result:

Channels of the LocalChannel tests are always closed when their event
loop group shuts down, which removes one possible source of the flaky
leak report.
@netty-project-bot netty-project-bot mentioned this pull request Oct 1, 2026
Auto-port 4.1: Use LocalIoHandler instead of DefaultEventLoop for LocalChannel tests in codec-http2 #17708
Merged
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
Port: Use LocalIoHandler instead of DefaultEventLoop for LocalChannel tests in codec-http2 (#17697) #17709
Merged
normanmaurer added a commit that referenced this pull request Oct 1, 2026
@netty-project-bot @normanmaurer
Auto-port 4.1: Use LocalIoHandler instead of DefaultEventLoop for Loc…
55e8a6a
…alChannel tests in codec-http2 (#17708)

Auto-port of #17697 to 4.1
Cherry-picked commit: d3817ad

---
Motivation:

Http2MultiplexTransportTest failed on CI in the LeakPresenceExtension
afterAll check ("Possible memory leak detected for resource scope")
although every test in the class passed. The check waits up to 5 seconds
for resources to be released, so something stayed open for good rather
than just shutting down slowly.

Several tests run LocalChannel / LocalServerChannel on a
DefaultEventLoop
and then call shutdownGracefully() without waiting. Unlike
LocalIoHandler (and NioIoHandler for the other tests in the class),
DefaultEventLoop does not close the channels registered with it when it
shuts down. A server-side child channel is therefore only closed if the
peer-close task still runs before the loop terminates. If it does not,
the channel and whatever it still holds (for example the large wrapped
payloads written by the auto-read tests added in #17617) is never
released, which the leak presence detector reports.

Modification:

- Use `new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory())`
instead of `new DefaultEventLoop()` in the LocalChannel based tests of
Http2MultiplexTransportTest, Http2MultiplexCodecBuilderTest and
Http2StreamChannelBootstrapTest. LocalIoHandler closes all registered
channels when the group shuts down. A single thread is kept so server
and client still share one event loop as before.

Result:

Channels of the LocalChannel tests are always closed when their event
loop group shuts down, which removes one possible source of the flaky
leak report.

Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Oct 1, 2026
@normanmaurer
Port: Use LocalIoHandler instead of DefaultEventLoop for LocalChannel…
add0311
… tests in codec-http2 (#17697) (#17709)

Motivation:

Http2MultiplexTransportTest failed on CI in the LeakPresenceExtension
afterAll check ("Possible memory leak detected for resource scope")
although every test in the class passed. The check waits up to 5 seconds
for resources to be released, so something stayed open for good rather
than just shutting down slowly.

Several tests run LocalChannel / LocalServerChannel on a
DefaultEventLoop
and then call shutdownGracefully() without waiting. Unlike
LocalIoHandler (and NioIoHandler for the other tests in the class),
DefaultEventLoop does not close the channels registered with it when it
shuts down. A server-side child channel is therefore only closed if the
peer-close task still runs before the loop terminates. If it does not,
the channel and whatever it still holds (for example the large wrapped
payloads written by the auto-read tests added in #17617) is never
released, which the leak presence detector reports.

Modification:

- Use `new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory())`
instead of `new DefaultEventLoop()` in the LocalChannel based tests of
Http2MultiplexTransportTest, Http2MultiplexCodecBuilderTest and
Http2StreamChannelBootstrapTest. LocalIoHandler closes all registered
channels when the group shuts down. A single thread is kept so server
and client still share one event loop as before.

Result:

Channels of the LocalChannel tests are always closed when their event
loop group shuts down, which removes one possible source of the flaky
leak report.
@mkurz mkurz mentioned this pull request Oct 7, 2026
HTTP/2: Respect read limits for frames queued at end of stream #17774
Open
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@netty-project-bot @pandareen
@normanmaurer @lltopk
Auto-port 4.1: HTTP/2: Fix stream stall when toggling auto-read on a …
068e146
…child channel (netty#17646)

Auto-port of netty#17617 to 4.1
Cherry-picked commit: ee269f5

---
Motivation:

When `setAutoRead()` is called on an `Http2StreamChannel` from a
different EventLoop than the one the channel is registered to (e.g., a
proxy mirroring writability state between streams on different
connections), a race condition can occur. This leaves the stream stalled
indefinitely because the auto-read state change may be reordered against
or race with read-processing on the stream channel's own EventLoop,
preventing the channel from resuming reads and sending flow-control
WINDOW_UPDATE frames.

This issue is described in netty#17600.

Modification:

Modified
`AbstractHttp2StreamChannel.Http2StreamChannelConfig.setAutoRead()` to
ensure the auto-read state change is always applied on the channel's own
EventLoop, similar to how `AUTO_STREAM_FLOW_CONTROL` is handled. The
method now:

1. Checks if the channel is registered and if the current thread is on
the channel's EventLoop
2. If so, applies the change immediately via `setAutoRead0()`
3. If not, schedules the change to run on the channel's EventLoop via
`execute()`

This ensures thread-safe, EventLoop-confined updates to the auto-read
state, preventing races with concurrent read-processing.

Added a comprehensive test
`crossThreadSetAutoReadResumesStalledStream()` that reproduces the
issue: it disables auto-read before data arrives (causing the stream to
stall once the 64KiB flow-control window is exhausted), then re-enables
auto-read from a foreign EventLoop. The test verifies that the stream
resumes and delivers the complete response body.

Result:

Fixes netty#17600. Http2StreamChannel can now safely have its auto-read state
toggled from any thread without risking a stalled stream. The fix
maintains EventLoop-confinement for all state changes while allowing
cross-thread calls to proceed safely.

---------

Co-authored-by: pandareen <[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 @normanmaurer @lltopk
Auto-port 4.1: Use LocalIoHandler instead of DefaultEventLoop for Loc…
3d8d152
…alChannel tests in codec-http2 (netty#17708)

Auto-port of netty#17697 to 4.1
Cherry-picked commit: d3817ad

---
Motivation:

Http2MultiplexTransportTest failed on CI in the LeakPresenceExtension
afterAll check ("Possible memory leak detected for resource scope")
although every test in the class passed. The check waits up to 5 seconds
for resources to be released, so something stayed open for good rather
than just shutting down slowly.

Several tests run LocalChannel / LocalServerChannel on a
DefaultEventLoop
and then call shutdownGracefully() without waiting. Unlike
LocalIoHandler (and NioIoHandler for the other tests in the class),
DefaultEventLoop does not close the channels registered with it when it
shuts down. A server-side child channel is therefore only closed if the
peer-close task still runs before the loop terminates. If it does not,
the channel and whatever it still holds (for example the large wrapped
payloads written by the auto-read tests added in netty#17617) is never
released, which the leak presence detector reports.

Modification:

- Use `new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory())`
instead of `new DefaultEventLoop()` in the LocalChannel based tests of
Http2MultiplexTransportTest, Http2MultiplexCodecBuilderTest and
Http2StreamChannelBootstrapTest. LocalIoHandler closes all registered
channels when the group shuts down. A single thread is kept so server
and client still share one event loop as before.

Result:

Channels of the LocalChannel tests are always closed when their event
loop group shuts down, which removes one possible source of the flaky
leak report.

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

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

4.2.19.Final

Development

Successfully merging this pull request may close these issues.

HTTP/2: changing Http2StreamChannelConfig#setAutoRead() from a different thread can stall or truncate a stream

Uh oh!

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

4 participants

@pandareen @normanmaurer @netty-project-bot @claude
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.