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 — Keep reading a closed QUIC stream until the end of its input by allthingssecurity · Pull Request #17755 · netty/netty Conversation
Contributor
Motivation: When a
quiche keeps the unread data and the FIN, which has three effects:
Reproduced on the real transport with the released 4.2.18 native library (the JNI code is unchanged since):
Modification:
An alternative is to send STOP_SENDING from Result: Closing a QUIC stream before the end of its input no longer leaks connection flow control credit, stream credit and the stream channel.
Prepared with Claude Code on behalf of allthingssecurity. 🤖 Generated with Claude Code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsMotivation: When a `QuicStreamChannel` is closed before the FIN of the remote peer was read, `QuicheQuicStreamChannel` never reads from the stream again: `recv()` only loops while the channel is active, and `readable()` only calls `recv()` when a read is pending. quiche keeps the unread data and the FIN, so: - the data keeps its connection flow control credit. A client that closes streams while responses are still arriving (for example cancelled requests) uses up the connection window, and after that no stream of the connection receives data anymore. - the stream is never completed and collected, so its stream credit is never returned to the remote peer. A server that closes streams before reading the request's FIN (for example after an early error response) stops the client from opening new streams once `initialMaxStreamsBidirectional` such streams were closed. - the stream channel is never removed from the streams of its `QuicChannel`, as that requires the FIN to be read. Modification: - `recv()` reads and drops what is left once the channel is closed, until the FIN is received or the stream was reset. - `readable()` calls `recv()` for a closed channel even if no read is pending, and `close()` drops what is left if the stream was readable already. - Add `QuicStreamLimitTest.testStreamLimitRestoredWhenStreamClosedBeforeEndOfInput` and `QuicStreamChannelCloseTest.testCloseBeforeEndOfInputReturnsFlowControlCredit`. Result: Closing a QUIC stream before the end of its input no longer leaks flow control credit, stream credit and the stream channel. Co-Authored-By: Claude Opus 5.5 <[email protected]> …the end of its input
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
🚨 All tests passed but jobs failed 🚨Failed Jobs without Test Failures❌ Build PR / windows-x86_64-java11-boringssl 🏷️ Commit: d1988a9 Rerun ControlsClick 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.
|
Could not create auto-port PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Port for 5.0: #17839 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Motivation: testCloseBeforeEndOfInputReturnsFlowControlCredit failed on 5.0 with "received only 131072 bytes". The port translated the server's QuicStreamChannel.SHUTDOWN_OUTPUT listener to ctx.shutdown(ChannelShutdownType.newInbound()), so the server never sent its FIN and the client never saw the end of the input. Modification: - Shut down the outbound side of the server stream after writing the response. - Forward the received ChannelShutdownType in the client stream handler of testCloseOutsideOfReadBeforeEndOfInputReturnsFlowControlCredit, as the original forwarded the user event. Result: The 5.0 tests match the semantics of the original tests from #17755.
#17755) (#17839) Motivation: When a `QuicStreamChannel` is closed before the FIN of the remote peer was read, `QuicheQuicStreamChannel` never reads from that stream again: - `recv()` only loops `while (active && readPending && readable)`, - `readable()` only calls `recv()` when a read is pending, - `close()` sends our FIN but leaves the receive side alone. quiche keeps the unread data and the FIN, which has three effects: 1. The data keeps its connection-level flow control credit, as quiche only returns credit for data the application consumed. A client that closes streams while responses are still arriving (cancelled requests, a common case) uses up the connection window. After that, no stream of the connection receives data anymore. 2. The stream is never completed and collected, so its stream credit is never returned to the remote peer (no MAX_STREAMS update). A server that closes streams before it read the request's FIN (for example after writing an early error response) stops the client from opening new streams once `initialMaxStreamsBidirectional` such streams were closed. 3. The closed stream channel is never removed from the streams of its `QuicChannel`, as `removeStreamFromParent()` requires the FIN to be read. Reproduced on the real transport with the released 4.2.18 native library (the JNI code is unchanged since): - Server with `initialMaxStreamsBidirectional(2)` that closes each stream on its first `channelRead`: the client completes 2 streams; creating the 3rd fails with `QUICHE_ERR_STREAM_LIMIT`, and `peerAllowedStreams(BIDIRECTIONAL)` stays 0. With a server that closes after the FIN, all 6 streams complete. - Client with `initialMaxData(256 KiB)` that closes each stream after the first chunk of a 64 KiB response: after 4 such requests, the next request gets no data at all and the connection idles out. Modification: - At the end of `recv()`, if the channel is closed, read and drop what is left (`discardInput(...)`) until quiche reports no more data, the FIN, or an error (stream reset or closed connection). `removeStreamFromParent()` then removes the stream once the end of the input was seen. - `readable()` calls `recv()` for a closed channel even if no read is pending, so data and the FIN that arrive after the close are dropped too. - `close()` drops what is left if the stream was readable already (when `close()` is called from `channelRead(...)`, `recv()` does it after its loop). - Add `QuicStreamLimitTest.testStreamLimitRestoredWhenStreamClosedBeforeEndOfInput`: the server closes each stream on its first read, before the client's FIN arrives; the client creates three streams in a row with a stream limit of 1 and checks that the server returns the stream credit (`QuicStreamLimitChangedEvent`) each time. - Add `QuicStreamChannelCloseTest.testCloseBeforeEndOfInputReturnsFlowControlCredit`: the client closes a stream after the first bytes of a response that is twice its connection window, then checks that the next response is received completely. An alternative is to send STOP_SENDING from `close()` (`stream_shutdown` of the read side), which also tells the peer to stop sending. It needs an application error code, which the transport does not know, and the receive side still has to be drained or tracked until the peer's FIN or RESET_STREAM arrives to remove the stream channel. This change keeps the current wire behaviour and only consumes what arrives. Result: Closing a QUIC stream before the end of its input no longer leaks connection flow control credit, stream credit and the stream channel. --------- Co-authored-by: Norman Maurer <[email protected]> --------- Co-authored-by: allthingssecurity <[email protected]>
|
@allthingssecurity @normanmaurer thanks for this fix! Just wanted to confirm that it resolves a real production issue for us. We run a QUIC-based proxy layer on netty's QUIC codec that multiplexes many short-lived streams over a single connection. A fraction of those streams are closed before the peer's We built against a 4.2.20 snapshot with this change, and the leak is gone. Connections that previously wedged now sustain heavy load (150k+ streams/hr per host) with only transient, self-recovering back-pressure under genuine concurrent-stall conditions; no runaway accumulation. Looking forward to the official 4.2.20.Final release with this fix; thanks for the quick turnaround and the thorough write-up. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
So good to hear this @jbaldassari . |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.