From e3515a3b30ea9922dd49aa104a8750b968f73904 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 15 Oct 2026 11:31:27 -0700 Subject: [PATCH] fix(qmux): grant 10,000 concurrent streams by default A session granted its peer 100 concurrent streams in each direction. An application that holds a stream per subscription, as MoQ does, silently stalls on MAX_STREAMS once it passes that: every later open waits on stream credit forever and nothing errors. Grant 10,000, matching what QUIC deployments of the same application use, in both the Rust and JS defaults. Co-Authored-By: Claude Opus 5.5 --- js/qmux/src/frame.ts | 4 ++-- js/qmux/src/session.test.ts | 21 +++++++++++++++++++++ js/qmux/src/session.ts | 8 ++++---- rs/qmux/README.md | 4 ++-- rs/qmux/src/config.rs | 8 ++++---- rs/qmux/tests/streams.rs | 18 +++++++++--------- 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/js/qmux/src/frame.ts b/js/qmux/src/frame.ts index 798b3b8a..4aaabd0f 100644 --- a/js/qmux/src/frame.ts +++ b/js/qmux/src/frame.ts @@ -221,8 +221,8 @@ export const RECOMMENDED_TRANSPORT_PARAMS: TransportParams = { initialMaxStreamDataBidiLocal: 262_144n, initialMaxStreamDataBidiRemote: 262_144n, initialMaxStreamDataUni: 262_144n, - initialMaxStreamsBidi: 100n, - initialMaxStreamsUni: 100n, + initialMaxStreamsBidi: 10_000n, + initialMaxStreamsUni: 10_000n, maxDatagramFrameSize: DEFAULT_MAX_RECORD_SIZE, maxRecordSize: DEFAULT_MAX_RECORD_SIZE, resetStreamAt: false, diff --git a/js/qmux/src/session.test.ts b/js/qmux/src/session.test.ts index 4c01d45c..dfa9ed80 100644 --- a/js/qmux/src/session.test.ts +++ b/js/qmux/src/session.test.ts @@ -1010,6 +1010,27 @@ describe("Session integration (scripted peer)", () => { session.close(); }); + test("the default config holds a thousand open streams", async () => { + const { session, peer } = connect(); + await session.ready; + peer.send({ type: "transport_parameters", params: peerParams() }); + + for (let i = 0n; i < 1_000n; i++) { + for (const dir of [Stream.Dir.Bi, Stream.Dir.Uni]) { + peer.send({ + type: "stream", + id: Stream.Id.create(i, dir, true), + data: new Uint8Array([1]), + fin: false, + }); + } + } + peer.send({ type: "ping_request", sequence: 1n }); + await waitFor(() => peer.has("ping_response") || sentClose(peer) !== undefined); + expect(sentClose(peer)).toBeUndefined(); + session.close(); + }); + // Regression: a STREAM frame delivered by the read loop after the session has // closed used to hit the already-closed incoming-stream controllers, and the // throw escaped as an unhandled rejection because #handleStreamFrame was an diff --git a/js/qmux/src/session.ts b/js/qmux/src/session.ts index 84c9faeb..96f87177 100644 --- a/js/qmux/src/session.ts +++ b/js/qmux/src/session.ts @@ -24,9 +24,9 @@ export type Version = Exclude; /** Configuration for a QMux session. */ export interface Config { - /** Max concurrent bidirectional streams the peer can open. */ + /** Max concurrent bidirectional streams the peer can open. Defaults to 10,000. */ maxStreamsBidi?: bigint; - /** Max concurrent unidirectional streams the peer can open. */ + /** Max concurrent unidirectional streams the peer can open. Defaults to 10,000. */ maxStreamsUni?: bigint; /** Connection-level receive window in bytes. */ maxData?: bigint; @@ -50,8 +50,8 @@ export interface Config { } const DEFAULT_CONFIG: Required = { - maxStreamsBidi: 100n, - maxStreamsUni: 100n, + maxStreamsBidi: 10_000n, + maxStreamsUni: 10_000n, maxData: 1_048_576n, maxStreamDataBidiLocal: 262_144n, maxStreamDataBidiRemote: 262_144n, diff --git a/rs/qmux/README.md b/rs/qmux/README.md index 57baf91f..93f8ffe3 100644 --- a/rs/qmux/README.md +++ b/rs/qmux/README.md @@ -51,8 +51,8 @@ async fn connect(addr: std::net::SocketAddr) -> Result { Every entry point takes a `Config` for flow control and timeouts: `session_config` on `tcp::Config` and `uds::Config`, `with_session_config` on the rest. The wire-format version and application protocol still come from the -builder or the handshake. The default grants a peer 100 concurrent streams in -each direction; raise `max_streams_bidi` and `max_streams_uni` if your +builder or the handshake. The default grants a peer 10,000 concurrent streams +in each direction; raise `max_streams_bidi` and `max_streams_uni` if your application holds more streams open at once. To run QMux over something the built-in modules don't cover, wrap any diff --git a/rs/qmux/src/config.rs b/rs/qmux/src/config.rs index 7ff0403d..4912b625 100644 --- a/rs/qmux/src/config.rs +++ b/rs/qmux/src/config.rs @@ -42,9 +42,9 @@ pub struct Config { /// How the application protocol is determined. See [`Protocol`]. pub protocol: Protocol, - /// Max concurrent bidirectional streams the peer can open. + /// Max concurrent bidirectional streams the peer can open. Default: 10,000. pub max_streams_bidi: u64, - /// Max concurrent unidirectional streams the peer can open. + /// Max concurrent unidirectional streams the peer can open. Default: 10,000. pub max_streams_uni: u64, /// Connection-level receive window in bytes. pub max_data: u64, @@ -99,8 +99,8 @@ impl Default for Config { Self { version: Version::QMux02, protocol: Protocol::None, - max_streams_bidi: 100, - max_streams_uni: 100, + max_streams_bidi: 10_000, + max_streams_uni: 10_000, max_data: 1_048_576, // 1 MB max_stream_data_bidi_local: 262_144, // 256 KB max_stream_data_bidi_remote: 262_144, // 256 KB diff --git a/rs/qmux/tests/streams.rs b/rs/qmux/tests/streams.rs index 6e89d399..04b46999 100644 --- a/rs/qmux/tests/streams.rs +++ b/rs/qmux/tests/streams.rs @@ -55,17 +55,17 @@ async fn held(config: Config, target: usize) -> usize { accepted.len() } -/// Applications such as MoQ hold a stream per subscription, so they need to -/// grant more than the default. +/// Applications such as MoQ hold a stream per subscription, so the default must +/// hold far more than a hundred open streams. #[tokio::test(start_paused = true)] -async fn configured_limit_holds_a_thousand_streams() { - let mut config = Config::default(); - config.max_streams_bidi = 1_000; - config.max_streams_uni = 1_000; - assert_eq!(held(config, 1_000).await, 1_000); +async fn default_config_holds_a_thousand_open_streams() { + assert_eq!(held(Config::default(), 1_000).await, 1_000); } #[tokio::test(start_paused = true)] -async fn default_limit_stalls_at_a_hundred_streams() { - assert_eq!(held(Config::default(), 1_000).await, 100); +async fn configured_limit_bounds_open_streams() { + let mut config = Config::default(); + config.max_streams_bidi = 100; + config.max_streams_uni = 100; + assert_eq!(held(config, 1_000).await, 100); }