Skip to content

quic: open_stream() waits for the peer to allow another stream - #55

Merged
pgit merged 1 commit into
masterfrom
quic-open-stream
Nov 24, 2026
Merged

pgit merged 1 commit into
masterfrom
quic-open-stream

Conversation

@pgit

@pgit pgit commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Closes #53. The design is the one in the issue's comment: opening a stream waits for the peer's MAX_STREAMS, the way a write waits for flow control credit.

API

  • quic::Connection::open_stream() is now a coroutine that waits until the peer allows another stream; async_open_stream(token) is its ASIO form, next to accept_stream() / async_accept_stream().
  • try_open_stream() is the old synchronous call: would_block at the peer's limit, and also while an open is waiting, so it cannot jump the queue.
  • A cancelled wait fails with errors::canceled and leaves the queue; when the connection ends, every waiting open fails with errors::connection_aborted.

Existing callers break at compile time (a structured binding of an IoTask does not compile). c-ares-async has to change its call when it next moves its pin, and can drop its own queue of waiting queries then.

Implementation

  • ngtcp2's extend_max_local_streams_bidi was registered as a no-op, shared with the remote one. It is now forwarded to a QuicApplication hook of its own; the remote one is no longer registered (optional in ngtcp2).
  • StreamApplication keeps the waiting opens in FIFO order and opens a stream for each one, inside that callback, for as long as the peer allows; the completion is posted. Each wait has a token, so a cancellation that comes after its stream has been handed over does nothing. The cancellation callback reaches the application through a weak pointer to the session.
  • HTTP/3's submit() is unchanged; only a comment in h3/client.cpp that pointed at the old call is updated.

Tests

test/test_quic.cpp, both write modes:

  • The test at a limit of two no longer polls with delay(10ms): try_open_stream() refuses, open_stream() waits.
  • A new fixture with max_streams = 1, for the cases the issue lists: the next open waits until the first stream is over at both ends, with the client doing nothing more; waiting opens get their streams in order; a cancelled open fails with canceled and takes no stream; a waiting open fails with connection_aborted when the server closes the connection, and when the client does.
  • With the wake-up taken out of the callback, the eight tests that depend on it fail at their 2 s guard and the two close tests still pass.

Run locally: the whole suite on build/ (gtest-parallel); the QUIC and guide tests on build-corosio, build-gcc, build-corosio-gcc, build-asan and build-corosio-asan (ASAN three times each, no reports); the docs target. Not run: the TSAN and h2v2 trees, check_package.sh (no public header includes anything new).

🤖 Generated with Claude Code

At the peer's stream limit, open_stream() failed with would_block, and
nothing told the caller when the limit went up again: the peer allows
another stream with MAX_STREAMS, a round trip after a stream is over at
both ends, so a caller that retried when its own stream ended still got
would_block and could only poll (#53).

MAX_STREAMS is flow control credit, and a write already waits for credit
instead of failing. Opening a stream now does too:

- open_stream() (async_open_stream() with a token on ASIO) waits until
  the peer allows another stream. Waiting opens are served in the order
  they started, each getting its stream opened for it as ngtcp2 reports
  the raised limit (extend_max_local_streams_bidi, now forwarded to the
  QuicApplication), so nothing can take it in between.
- A cancelled wait leaves the queue and fails with canceled; when the
  connection ends, every waiting open fails with connection_aborted.
- try_open_stream() is the old synchronous call, failing with
  would_block at the limit and also while an open is waiting.

The rename breaks callers at compile time, not silently. HTTP/3's
submit() is unchanged.

Closes #53

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pgit
pgit merged commit 1939bef into master Nov 24, 2026
12 checks passed
@pgit
pgit deleted the quic-open-stream branch November 24, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QUIC: no way to wait for a stream at the peer's stream limit

1 participant