quic: add Http3Session, so you can explicitly pick the app protocol #65993
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
efekrskl
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
autoStartdesign)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 (
QuicSessionandHttp3Session) 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 asmaintoday) or it's started manually after settingautoStart: false.To manually start a session, you call
Http3Session.start(conn)orQuicSession.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 clientopenedpromise 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).autoStartchanges the type of the clientconnect()call/server onsession callback: if you autoStart, it always returns/passes the started session instance - in practice, this behaves very similar tomain. If you setautoStart: false, it always returns/passes aQuicConnectioninstead.alpnis now a required option. Even withautoStart, I really don't think we should default to HTTP/3 in an API that isn't callednode:http3. In practice with autoStartconnect({ 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
QuicSessionintoQuicConnection(lifecycle APIs, TLS & transport fields), an internalQuicSessionBasebase 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) andQuicSession/Http3Session(inheriting fromQuicSessionBase, 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 asQuicConnection(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 onh3via 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
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: trueorautoStart: falsecases, 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.