GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
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
|
|
I don't think this is the right fix... It's just a workaround |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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
|
You're right, thanks for pushing back. The first version only moved Root cause
Only the Why toggling auto-read triggers itEach Doing the flip from another EventLoop only makes this more likely. It isn't a threading bug: it reproduces on a single thread. Changes
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Closing this one... will work on a proper fix. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@pandareen did you sign our ICLA ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
yes |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This fix looks good and makes sense... waiting for the CI. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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]>
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
|
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@pandareen I did add some more code as the fix was not 100 % correct before. Now it should be |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
🚨 TestLens detected 1 failed test 🚨Here is what you can do:
Test SummaryBuild PR / macos-x86_64-java11-boringssl build > Netty/Transport/Native/KQueue
🏷️ Commit: c7ed8b6 Test FailuresKQueueDatagramUnicastIPv6MappedTest > testSimpleSendHeapByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-x86_64-java11-boringssl build)Rerun ControlsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Auto-port PR for 4.1: #17646 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Could not create auto-port PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Port for 5.0: #17650 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…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]>
…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]>
… 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.
…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]>
… 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.
…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]>
…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]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
HTTP/2: changingHttp2StreamChannelConfig#setAutoRead() from a different thread can stall or truncate a stream
There was an error while loading. Please reload this page.