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 — Quic: don't permanently consume stream ids when createStream(...) fails by Echo009 · Pull Request #18311 · netty/netty

Conversation

@Echo009

@Echo009 Echo009 commented Nov 8, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

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.

All reactions
@Echo009
Echo009 force-pushed the quic-stream-id-not-consumed-on-failed-create branch 2 times, most recently from 320a9ba to 6a86656 Compare November 8, 2026 04:44
@Echo009
Quic: don't permanently consume stream ids when createStream(...) fails
b64a112
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]>
@Echo009
Echo009 force-pushed the quic-stream-id-not-consumed-on-failed-create branch from 5c312c6 to b64a112 Compare November 9, 2026 04:00
@Echo009

Echo009 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

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(...).)

All reactions

Sorry, something went wrong.

Uh oh!

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

@vietj

vietj commented Nov 9, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

@Echo009 I am only contributor on this project

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer

normanmaurer commented Nov 9, 2026

Copy link
Copy Markdown
Member

@Echo009 please sign our icla and let me know once you have done this: https://netty.io/s/icla

All reactions

Sorry, something went wrong.

Uh oh!

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

normanmaurer
normanmaurer reviewed Nov 9, 2026
View reviewed changes
Comment thread codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicheQuicChannel.java Resolved

Uh oh!

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

@Echo009
Quic: don't mark streamCreditsInitialized volatile
292b9bc
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

Echo009 commented Nov 9, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

@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!

All reactions

Sorry, something went wrong.

Uh oh!

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

@testlens-app

testlens-app Bot commented Nov 9, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 292b9bc
▶️ Tests: 43636 executed
⚪️ Checks: 26/26 completed


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 added this to the 4.2.21.Final milestone Nov 9, 2026
@normanmaurer normanmaurer added the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Nov 9, 2026
@normanmaurer
normanmaurer merged commit f0dc37e into netty:4.2 Nov 9, 2026
28 checks passed

Uh oh!

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

@netty-project-bot

netty-project-bot commented Nov 9, 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 added a commit that referenced this pull request Nov 9, 2026
@normanmaurer @Echo009
Port 5: Quic: don't permanently consume stream ids when createStream(…
1dd4cbc
…...) 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]>
@chrisvest chrisvest removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@normanmaurer normanmaurer normanmaurer left review comments

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.21.Final

Development

Successfully merging this pull request may close these issues.

QUIC: createStream() permanently consumes a stream ID on STREAM_LIMIT_ERROR; peerAllowedStreams() then over-reports and the connection degrades irreversibly

Uh oh!

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

5 participants

@Echo009 @vietj @normanmaurer @netty-project-bot @chrisvest
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.