GeezerVison is showing github.com — Quic: don't permanently consume stream ids when createStream(...) fails by Echo009 · Pull Request #18311 · netty/netty
Conversation
Echo009
commented
Nov 8, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Motivation:
A failed QuicChannel.createStream(...) permanently consumes the allocated stream id: QuicheQuicChannel.connectStream allocates via QuicStreamIdGenerator before trying the implicit open, and on failure the id is never returned. quiche rejects the implicit open by stream id position and advances nothing, so every failed attempt raises the position of all future stream ids past the peer's limit. After that createStream(...) keeps failing with STREAM_LIMIT_ERROR forever — even once MAX_STREAMS restored the limit — while peerAllowedStreams(...) and QuicStreamLimitChangedEvent still report capacity, which breaks the documented contract of peerAllowedStreams(...). Details and a minimal reproducer (a pure netty loopback test that mirrors QuicStreamLimitTest.testStreamLimitEnforcedWhenCreatingViaClient plus one extra createStream): #18310.
Modifications:
- Fail fast in
QuicheQuicChannel.connectStream(...) when the cached stream credit for the direction is <= 0, without allocating a stream id. The caches are only trusted once they were refreshed from quiche at least once (tracked by streamCreditsInitialized): before the first refresh they are 0 even though the peer may have announced credits — e.g. the server side creates streams as soon as the channel becomes active, before any refresh happened — so in that window we fall through to quiche, where the rollback below handles a rejection.
- Roll back the last allocated id in
QuicStreamIdGenerator when quiche rejected the implicit open with STREAM_LIMIT_ERROR. quiche provably created no state for the stream in that case (the limit is checked in get_or_create before anything is inserted or counted), and connectStream(...) as well as the cache refresh both run on the connection eventloop, so the id is still the frontier. Other errors might have left state behind and are not rolled back. This also covers connections that already carried consumed ids.
- Refresh the cached credits on
<= 0 instead of == 0. A negative cached value is reachable: MAX_STREAMS can raise the peer's limit while the cached credits are still non-zero (the refresh only triggers once a direction hit 0), so the cache can legitimately lag behind quiche's real credits; createStream(...) then keeps succeeding on quiche's real credits while the cached count is decremented past zero, after which an == 0 check never matches again and peerAllowedStreams(...) is frozen below zero forever. With the fail-fast check in place crossing zero is no longer possible, so this is a safety net that also recovers an already-negative cached value on the next received packet.
- Add
QuicStreamIdGeneratorTest locking down the rollback semantics: only the most recently allocated id of a direction is rolled back (older ids may already have an open stream in quiche), a rolled-back id is handed out again, and the two directions are independent.
- Add
testStreamCreationSucceedsAfterFailedCreationAndLimitRestoredViaClient{Bidirectional,Unidirectional} to QuicStreamLimitTest, which fail before and pass after this change. The test also hammers createStream(...) repeatedly while the limit is exhausted, proving failed attempts consume no stream ids: otherwise the creation after the restore would fail with STREAM_LIMIT_ERROR again as the stream id position moved past the limit.
Result:
createStream(...) no longer permanently consumes stream ids when it fails with STREAM_LIMIT_ERROR, and peerAllowedStreams(...) keeps its documented meaning after a limit restore. Fixes #18310.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Motivation:
A failed QuicChannel.createStream(...) permanently consumes the allocated
stream id: QuicheQuicChannel.connectStream allocates via QuicStreamIdGenerator
before trying the implicit open, and on failure the id is never returned.
quiche rejects the implicit open by stream id position and advances nothing,
so every failed attempt raises the position of all future stream ids past
the peer's limit. After that createStream(...) keeps failing with
STREAM_LIMIT_ERROR forever, even once MAX_STREAMS restored the limit, while
peerAllowedStreams(...) and QuicStreamLimitChangedEvent still report
capacity, which breaks the documented contract of peerAllowedStreams(...).
Details and a minimal reproducer: netty#18310.
Modifications:
- Fail fast in QuicheQuicChannel.connectStream(...) when the cached stream
credit for the direction is <= 0, without allocating a stream id. The
caches are only trusted once they were refreshed from quiche at least
once: before the first refresh they are 0 even though the peer may have
announced credits (e.g. the server side creates streams as soon as the
channel becomes active, before any refresh happened), so in that window
we fall through to quiche and let the rollback handle a rejection.
- Roll back the last allocated id in QuicStreamIdGenerator when quiche
rejected the implicit open with STREAM_LIMIT_ERROR: quiche created no
state for the stream in that case, and connectStream(...) as well as the
cache refresh both run on the connection eventloop, so the id is still
the frontier. Other errors might have left state behind and are not
rolled back.
- Refresh the cached credits on <= 0 instead of == 0: MAX_STREAMS can raise
the peer's limit while the cached credits are still non-zero (the refresh
only triggers once a direction hit 0), so the cache can legitimately lag
behind quiche and be decremented past zero by later successful creations,
after which an == 0 check would never match again and peerAllowedStreams(...)
would be frozen below zero forever.
- Add QuicStreamIdGeneratorTest locking down the rollback semantics: only
the most recently allocated id of a direction is rolled back, a rolled-back
id is handed out again, and the two directions are independent.
- Add testStreamCreationSucceedsAfterFailedCreationAndLimitRestoredViaClient
{Bidirectional,Unidirectional} to QuicStreamLimitTest, which fails before
and passes after this change. The test also hammers createStream(...)
repeatedly while the limit is exhausted, proving failed attempts consume
no stream ids.
Result:
createStream(...) no longer permanently consumes stream ids when it fails
with STREAM_LIMIT_ERROR and peerAllowedStreams(...) keeps its documented
meaning after a limit restore. Fixes netty#18310.
Signed-off-by: Echo009 <[email protected]>
|
Hi @vietj, the workflows on this PR have not run yet (Workflow runs completed with no jobs) — as a first-time contributor the run needs a maintainer approval. Could you give it an "Approve and run" when convenient? Thank you!
(Saw your #18313 in the same area — the changes don't overlap, this one only touches the stream id allocation / credit caching in connectStream(...) and processReceived(...).)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
vietj
commented
Nov 9, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
@Echo009 I am only contributor on this project
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Motivation:
The field is only written in processReceived(...) and read in the
connectStream(...) fast-path check, both confined to the event loop
thread (the public createStream(...) entry already dispatches via
eventLoop().execute(...)), so no synchronization is needed.
Result:
No volatile access overhead for the event-loop confined flag.
Signed-off-by: Echo009 <[email protected]>
Echo009
commented
Nov 9, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
@normanmaurer Thanks for the review! Agreed — removed the volatile: the field is only written in processReceived(...) and read in the connectStream(...) fast-path check, both confined to the event loop thread (the public createStream(...) entry already dispatches via eventLoop().execute(...)), so no synchronization is needed. Pushed as 292b9bc.
Also: I've signed the ICLA via https://netty.io/s/icla. The CI workflows on this PR still show no jobs — could you please approve and run them when convenient? Thanks!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
✅ All tests passed ✅
🏷️ Commit: 292b9bc
▶️ Tests: 43636 executed
⚪️ Checks: 26/26 completed
Learn more about TestLens at testlens.app/docs.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Could not create auto-port PR.
Got conflicts when cherry-picking onto 5.0.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
normanmaurer
added a commit
that referenced
this pull request
Nov 9, 2026
…...) fails (#18311) (#18317)
Motivation:
A failed `QuicChannel.createStream(...)` permanently consumes the
allocated stream id: `QuicheQuicChannel.connectStream` allocates via
`QuicStreamIdGenerator` before trying the implicit open, and on failure
the id is never returned. quiche rejects the implicit open by stream id
position and advances nothing, so every failed attempt raises the
position of all future stream ids past the peer's limit. After that
`createStream(...)` keeps failing with `STREAM_LIMIT_ERROR` forever —
even once MAX_STREAMS restored the limit — while
`peerAllowedStreams(...)` and `QuicStreamLimitChangedEvent` still report
capacity, which breaks the documented contract of
`peerAllowedStreams(...)`. Details and a minimal reproducer (a pure
netty loopback test that mirrors
`QuicStreamLimitTest.testStreamLimitEnforcedWhenCreatingViaClient` plus
one extra `createStream`): #18310.
Modifications:
- Fail fast in `QuicheQuicChannel.connectStream(...)` when the cached
stream credit for the direction is `<= 0`, without allocating a stream
id. The caches are only trusted once they were refreshed from quiche at
least once (tracked by `streamCreditsInitialized`): before the first
refresh they are `0` even though the peer may have announced credits —
e.g. the server side creates streams as soon as the channel becomes
active, before any refresh happened — so in that window we fall through
to quiche, where the rollback below handles a rejection.
- Roll back the last allocated id in `QuicStreamIdGenerator` when quiche
rejected the implicit open with `STREAM_LIMIT_ERROR`. quiche provably
created no state for the stream in that case (the limit is checked in
`get_or_create` before anything is inserted or counted), and
`connectStream(...)` as well as the cache refresh both run on the
connection eventloop, so the id is still the frontier. Other errors
might have left state behind and are not rolled back. This also covers
connections that already carried consumed ids.
- Refresh the cached credits on `<= 0` instead of `== 0`. A negative
cached value is reachable: MAX_STREAMS can raise the peer's limit while
the cached credits are still non-zero (the refresh only triggers once a
direction hit `0`), so the cache can legitimately lag behind quiche's
real credits; `createStream(...)` then keeps succeeding on quiche's real
credits while the cached count is decremented past zero, after which an
`== 0` check never matches again and `peerAllowedStreams(...)` is frozen
below zero forever. With the fail-fast check in place crossing zero is
no longer possible, so this is a safety net that also recovers an
already-negative cached value on the next received packet.
- Add `QuicStreamIdGeneratorTest` locking down the rollback semantics:
only the most recently allocated id of a direction is rolled back (older
ids may already have an open stream in quiche), a rolled-back id is
handed out again, and the two directions are independent.
- Add
`testStreamCreationSucceedsAfterFailedCreationAndLimitRestoredViaClient{Bidirectional,Unidirectional}`
to `QuicStreamLimitTest`, which fail before and pass after this change.
The test also hammers `createStream(...)` repeatedly while the limit is
exhausted, proving failed attempts consume no stream ids: otherwise the
creation after the restore would fail with `STREAM_LIMIT_ERROR` again as
the stream id position moved past the limit.
Result:
`createStream(...)` no longer permanently consumes stream ids when it
fails with `STREAM_LIMIT_ERROR`, and `peerAllowedStreams(...)` keeps its
documented meaning after a limit restore. Fixes #18310.
---------
Signed-off-by: Echo009 <[email protected]>
(cherry picked from commit f0dc37e)
---------
Signed-off-by: Echo009 <[email protected]>
Co-authored-by: Echo009 <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
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.
|