Skip to content

quic: do not destroy incoming streams that have a consumer - #65335

Merged
nodejs-github-bot merged 5 commits into
nodejs:mainfrom
trivenay:quic-stream-consumer-gate
Aug 20, 2026
Merged

quic: do not destroy incoming streams that have a consumer#65335
nodejs-github-bot merged 5 commits into
nodejs:mainfrom
trivenay:quic-stream-consumer-gate

Conversation

@trivenay

Copy link
Copy Markdown
Contributor

Fixes: #64192

An incoming QUIC stream is currently destroyed at arrival unless the session has an onstream callback. That check is narrower than the ways a stream can actually be consumed: on an HTTP/3 session, the application layer drives incoming request streams through the session-level stream callbacks (onheaders, ontrailers, oninfo, onwanttrailers), and onstream is legitimately absent. Today such streams are destroyed out from under the h3 machinery, and the practical workaround is registering stub onstream handlers just to keep streams alive (as noted in the issue and in the WebTransport work in #63827).

This changes the arrival check to the broader invariant discussed in the issue: destroy an incoming stream only when the session has no consumer at all for it.

A consumer is either:

  • an onstream callback (any negotiated protocol), or
  • session-level stream callbacks, when the negotiated application actually produces header events. This is checked through the existing headersSupported session state, which the C++ side computes once when it selects the application from the negotiated ALPN — so the JS side reads a stored conclusion rather than re-deriving ALPN rules.

Notes on scope and safety:

  • Sessions with no consumers keep the current destroy-plus-warning behavior, so unconsumed streams cannot accumulate and hold flow control credit or MAX_STREAMS slots. (Kept streams that go idle are additionally bounded by streamIdleTimeout.)
  • The check is on the callback container, not on individual callback names — when a future consumer such as onsessionid (quic: Webtransport support quic/http 3 #63827) lands in the session-level stream callbacks, it participates with no further changes.
  • This path cannot affect HTTP/3's internal streams: control and QPACK streams are consumed inside nghttp3 and never exposed to JS (Http3Application::ReceiveStreamOpen), so only bidirectional request streams ever reach this check.
  • The check is not racy: callbacks are constructor-time configuration (listen()/connect() options), attached synchronously before the handshake that must complete before any peer stream can arrive, and the decision reads only session configuration — never stream content.

The new test covers both sides of the predicate: an HTTP/3 request completes on a session with only onheaders registered and no onstream (destroyed before this change), and stream callbacks registered on a session whose negotiated application cannot run them do not keep streams alive (destroyed with the warning, as before). The test was also validated against a build without this change, where the first case fails as expected. The existing test-quic-stream-uni-no-onstream continues to cover the no-callbacks-at-all case.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/quic

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. quic Issues and PRs related to the QUIC implementation / HTTP/3. labels Aug 16, 2026
@trivenay
trivenay force-pushed the quic-stream-consumer-gate branch from 3b6d1fb to aa4680a Compare August 16, 2026 19:49
@codecov

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.12%. Comparing base (f3a8f1a) to head (7ab7790).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65335      +/-   ##
==========================================
+ Coverage   90.10%   90.12%   +0.02%     
==========================================
  Files         752      752              
  Lines      252207   252250      +43     
  Branches    47446    47444       -2     
==========================================
+ Hits       227254   227346      +92     
+ Misses      16261    16206      -55     
- Partials     8692     8698       +6     
Files with missing lines Coverage Δ
lib/internal/quic/quic.js 100.00% <100.00%> (ø)
lib/internal/quic/state.js 100.00% <100.00%> (ø)

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread lib/internal/quic/quic.js Outdated
@trivenay
trivenay force-pushed the quic-stream-consumer-gate branch from aa4680a to ae555c6 Compare August 17, 2026 12:45
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikr trivikr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update quic.md to reflect this behavior? It currently says all peer-initiated streams arrive through session.onstream. This PR makes onstream optional when the negotiated application supports configured stream callbacks - for example, HTTP/3 requests consumed through onheaders. The general stream description, session.onstream docs, and HTTP/3 server example should clarify this.

@trivenay

Copy link
Copy Markdown
Contributor Author

@trivikr Updated quic.md in a fixup commit: the general stream description and session.onstream now note that stream-level callbacks count as a consumer for applications that support them (e.g. HTTP/3), and the minimal HTTP/3 server example calls out that onstream is optional there. Also converted the earlier follow-up commit to a fixup.

@trivenay
trivenay force-pushed the quic-stream-consumer-gate branch from ae555c6 to 3b48565 Compare August 18, 2026 22:46
Comment thread lib/internal/quic/quic.js Outdated
An incoming stream was destroyed unless the session had an onstream
callback, even when session-level stream callbacks (onheaders et al)
were registered and the negotiated application (HTTP/3) would drive
the stream through them. Users had to register stub onstream handlers
just to keep their streams alive.

Destroy an incoming stream only when the session has no consumer for
it at all: no onstream callback, and no session-level stream callbacks
runnable on the negotiated application (checked via the existing
headersSupported session state, computed when the application is
selected from ALPN). Sessions with no consumers keep the current
destroy-and-warn behavior so unconsumed streams cannot accumulate and
hold flow control credit.

On HTTP/3 sessions only bidirectional request streams reach this path;
control and QPACK streams are consumed internally by nghttp3 and are
never exposed to JavaScript.

Fixes: nodejs#64192

Signed-off-by: Naman Trivedi <trivenay@amazon.com>
Signed-off-by: Naman Trivedi <trivenay@amazon.com>
Signed-off-by: Naman Trivedi <trivenay@amazon.com>
Signed-off-by: Naman Trivedi <trivenay@amazon.com>
Signed-off-by: Naman Trivedi <trivenay@amazon.com>
@trivenay
trivenay force-pushed the quic-stream-consumer-gate branch from 3b48565 to 7ab7790 Compare August 19, 2026 22:07
@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 19, 2026
@trivikr trivikr added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Aug 19, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 20, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikr trivikr added commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. commit-queue Add this label to land a pull request using GitHub Actions. labels Aug 20, 2026
@nodejs-github-bot
nodejs-github-bot merged commit fd5b135 into nodejs:main Aug 20, 2026
79 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in fd5b135

@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. quic Issues and PRs related to the QUIC implementation / HTTP/3.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quic: Should QuicStream be destroyed, if onstream is not set

4 participants