Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/qmux/src/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions js/qmux/src/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions js/qmux/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export type Version = Exclude<WireFormat, "webtransport">;

/** 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;
Expand All @@ -50,8 +50,8 @@ export interface Config {
}

const DEFAULT_CONFIG: Required<Config> = {
maxStreamsBidi: 100n,
maxStreamsUni: 100n,
maxStreamsBidi: 10_000n,
maxStreamsUni: 10_000n,
Comment on lines +53 to +54

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bound unread streams before granting 10,000 by default

When an application does not consume its incoming-stream readers, a peer can now send empty, non-FIN STREAM frames for 10,000 bidi and 10,000 uni IDs; #handleStreamFrame eagerly constructs Web Streams and retains them in IncomingStreamQueue.#pending and the stream maps. Empty frames consume no connection flow-control credit, so the unchanged 1 MiB maxData does not constrain this remotely triggered allocation, while this change raises the previous cap by 100×. Add a separate bound or lazy representation for unaccepted streams before advertising this grant by default, and benchmark memory scaling across stream counts.

AGENTS.md reference: AGENTS.md:L57-L58

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Measured, not fixed here. A peer that opens every stream it is granted and never has them accepted costs:

Grant per direction Streams JS heap (empty, non-FIN frames) Rust RSS (1 byte held each, both ends)
100 200 2.0 MB 2.1 MB
1,000 2,000 6.1 MB 16 MB
10,000 20,000 61 MB (about 3.2 KB per stream) 69 MB (about 1.7 KB per stream per end)

So the worst case per session grows from about 2 MB to about 35 to 60 MB. That is the same exposure a QUIC endpoint takes when it grants 10,000 streams, which is the grant MoQ already uses over QUIC, and it is linear in the grant, so a deployment that needs a tighter bound can set max_streams_* explicitly through the builder config from #426. I'd keep the default at 10,000 and treat a lazy representation (or a separate bound) for unaccepted streams as a follow-up hardening, rather than block the silent-stall fix on it. The maintainer may decide otherwise.

(Written by Claude Opus 5.5)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Accepted as parity with QUIC: a session that grants 10,000 streams takes the same exposure over either transport, and a deployment that needs a tighter bound sets max_streams_* through the builder config. No follow-up planned.

(Written by Claude Opus 5.5)

maxData: 1_048_576n,
maxStreamDataBidiLocal: 262_144n,
maxStreamDataBidiRemote: 262_144n,
Expand Down
4 changes: 2 additions & 2 deletions rs/qmux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ async fn connect(addr: std::net::SocketAddr) -> Result<Session, Error> {
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
Expand Down
8 changes: 4 additions & 4 deletions rs/qmux/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions rs/qmux/tests/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading