← Back to Pull requests

quic: add Http3Session, so you can explicitly pick the app protocol #65993

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Sep 11, 2026 22:36 UTC
Author

This extracts dynamic application attach from #63995. This is still very much under debate, so I'll try to explain thoroughly:

(EDIT: updated to the connection/session distinction and updated autoStart design)

The visible API changes

Added QuicConnection: this represents the core QUIC transport state and lifecycle - but not the application protocol communication on top.
There's now two session classes (QuicSession and Http3Session) which each represent the application protocol on top of the transport, and expose the protocol-relevant stream/datagram APIs for that.
A session is started on top of a connection. It either starts automatically based on the ALPN negotiation (autoStart: true, the default, same as main today) or it's started manually after setting autoStart: false.
To manually start a session, you call Http3Session.start(conn) or QuicSession.start(conn). You must do this before the end of the tick when the connection is exposed (the tick when the server onsession callback fires, or the client opened promise resolves). If you don't, the connection is closed automatically.
The session owns the connection: you can only have one per connection, in both manual & automatic cases it must always be started before any communication happens, and userland can reach the raw connection details via session.connection (but my expectation with the design here is that you mostly don't need to).
autoStart changes the type of the client connect() call/server onsession callback: if you autoStart, it always returns/passes the started session instance - in practice, this behaves very similar to main. If you set autoStart: false, it always returns/passes a QuicConnection instead.
alpn is now a required option. Even with autoStart, I really don't think we should default to HTTP/3 in an API that isn't called node:http3. In practice with autoStart connect({ alpn: 'h3' }) is now all you need to specify to get an Http3Session back, and that seems reasonable to me.

Changes

This implement this, this PR splits QuicSession into QuicConnection (lifecycle APIs, TLS & transport fields), an internal QuicSessionBase base class (the common parts of the app session APIs: mirroring some very common lifecycle APIs from the connection, some callback handling, mirroring datagram APIs for now) and QuicSession/Http3Session (inheriting from QuicSessionBase, exposing the protocol-specific APIs).

This doesn't change the C++ internal structure: most notably it doesn't refactor them to match the changed JS API, so C++ still just has Session + Application, which JS exposes as QuicConnection (part of the native session API) + Quic/Http3Session (the rest of the native session API, tightly integrated with the application behaviour). I've left that as is for now since it works and it keeps the diff manageable, but we could clean up to clarify this later.

There are some other smaller C++ changes though to support the actual change: exposing a manual application start API (StartApplication), making various APIs work if no session has been started yet during manual start (meaning no application is present), and shutting down the connection if there's no session started by the deadline (RequireApplication).

There was a complicated optimization here before, which is now gone: deferring manual session start so that it just set a state field from JS, and then the start happened later on when the application was actually required. This avoided the JS->native call, but added lots of complexity. Now that this is just opt-in for specialist use cases I don't think it's worth it - better to skip it & simplify.

Why add ~~dynamic attach~~ manual session start

It's useful to be able to do raw QUIC with a HTTP/3 ALPN. This lets you test weird behaviours (much like to how our test suite occasionally drives HTTP/2 over raw TCP) or use an alternative HTTP/3 implementation.
It's useful to be able to choose to do HTTP/3 with a non-HTTP/3 ALPN. For HTTP/2 this has been used quite a bit, e.g. weird internal protocols, gRPC ALPNs, etc. Even today for HTTP/3 it's been used for various HTTP/3 drafts as h3-. It's perfectly valid to do this - if you agree on h3 via ALPN you should speak HTTP/3, but the inverse is not required.
Controlling this from JS provides a structure to support splitting the APIs themselves, so we can separate the HTTP/3 & QUIC APIs (soon: QuicStream vs Http3Stream) and make them both easier to use (e.g. no non-functional HTTP/3 methods on pure QUIC streams).
Dynamic configuration of the layers provides a staging point for any future work towards things like QMUX (HTTP/3 over QUIC-like APIs, not actual QUIC) where we'd need to split "application protocol" from "QUIC implementation" anyway.

Demo

await listen((connection) => {
  // Look at the connection and synchronously decide which session to start:
  if (connection.alpnProtocol === 'my-special-h3-alpn') {
    const h3Session = Http3Session.start(connection);
  } else {
    // Do raw QUIC everywhere else, even with h3 ALPN if you want:
    const rawQuic = QuicSession.start(connection);
  }
}, {
  alpn: ['h3', 'my-special-h3-alpn', 'other'],
  autoStart: false,
  ...
});

const clientConnection = await connect(address, {
  alpn: 'h3',
  autoStart: false
  ...
});

await clientConnection.opened;
// Synchronously start here after `opened` resolves and you have all conn details:
const h3Session = Http3Session.start(clientConnection);
// ... do client HTTP/3 things

In both cases, manually starting the session is possible strictly until the MakeCallback call for this existing event returns - there's no extra tick or delay introduced. If you don't do it by the, the connection is closed automatically and later calls fail.

Performance

Still no measureable impact I can see in either autoStart: true or autoStart: false cases, even despite removing the optimization.

What this PR does not do

There's many things not included here:

It doesn't rename 100% of 'session' public APIs to 'connection'. I've done all the obvious and easy parts, but I've avoided some unnecessary changes just to keep the diff manageable, and some cases are ambiguous anyway e.g. diagnostic channels (still quic.session.). Debatable, happy to change more..
It doesn't change the HTTP/3 settings APIs. There's more to do here, not huge but it's not strictly tied to this and I'd like to try to keep this PR smaller if I can.
It doesn't change the HTTP/3 streams. Bigger change, definitely interesting but leaving it for now.
It doesn't refactor the C++ internals. There's some cleanup & clarification possible here to match this I think, and some improvements I'm interested in making to Application generally, but it's large and will take more debate - better to defer.
Various other pre-existing small bugs & details I've run into - there are more things improve, but for basically any pre-existing issue I'd like to handle it separately so we can get this in first and work in parallel instead.

Diff: 650 lines (+487 / -163) across 8 files Reviewer: efekrskl Review duration: 115034m
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
0.59
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
44%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.388
Shallow Review Depth shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #65993"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 44.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 59% (MEDIUM) · Higher = larger blast radius
59%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 44.7% · Lower = rushed or shallow review
44.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 32.6% · Safe to merge
32.6%
Repository