Repository navigation
quic: open_stream() waits for the peer to allow another stream - #55
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 toaccept_stream()/async_accept_stream().try_open_stream()is the old synchronous call:would_blockat the peer's limit, and also while an open is waiting, so it cannot jump the queue.errors::canceledand leaves the queue; when the connection ends, every waiting open fails witherrors::connection_aborted.Existing callers break at compile time (a structured binding of an
IoTaskdoes 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
extend_max_local_streams_bidiwas registered as a no-op, shared with the remote one. It is now forwarded to aQuicApplicationhook of its own; the remote one is no longer registered (optional in ngtcp2).StreamApplicationkeeps 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.submit()is unchanged; only a comment inh3/client.cppthat pointed at the old call is updated.Tests
test/test_quic.cpp, both write modes:delay(10ms):try_open_stream()refuses,open_stream()waits.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 withcanceledand takes no stream; a waiting open fails withconnection_abortedwhen the server closes the connection, and when the client does.Run locally: the whole suite on
build/(gtest-parallel); the QUIC and guide tests onbuild-corosio,build-gcc,build-corosio-gcc,build-asanandbuild-corosio-asan(ASAN three times each, no reports); thedocstarget. Not run: the TSAN and h2v2 trees,check_package.sh(no public header includes anything new).🤖 Generated with Claude Code