Skip to content

Return InvalidStreamState from stream_send() for collected streams#2507

Open
schiemon wants to merge 1 commit into
cloudflare:masterfrom
schiemon:fix/stream-send-done-on-collected-stream
Open

Return InvalidStreamState from stream_send() for collected streams#2507
schiemon wants to merge 1 commit into
cloudflare:masterfrom
schiemon:fix/stream-send-done-on-collected-stream

Conversation

@schiemon

@schiemon schiemon commented Jun 7, 2026

Copy link
Copy Markdown

When a stream has been completed and garbage collected (for example after the peer sends STOP_SENDING, the fin bit is received, and the data is drained via stream_recv()), a subsequent stream_send() call hits get_or_create() for an id that is in the collected set, which returns Error::Done. That error was forwarded unchanged, so callers saw Done (normally "no capacity") for a stream that no longer exists.

Map that case to Error::InvalidStreamState instead, matching the behaviour of stream_recv() which already returns InvalidStreamState for a non-existent stream. This lets applications distinguish a lack of send capacity from an invalid stream id without an extra stream_writable() check.

Fixes #1695

@schiemon schiemon force-pushed the fix/stream-send-done-on-collected-stream branch from 044aae0 to c6cad67 Compare June 7, 2026 19:35
@schiemon schiemon marked this pull request as ready for review June 7, 2026 19:36
@schiemon schiemon requested a review from a team as a code owner June 7, 2026 19:36
When a stream has been completed and garbage collected (for example
after the peer sends STOP_SENDING, the fin bit is received, and the
data is drained via stream_recv()), a subsequent stream_send() call
hits get_or_create() for an id that is in the collected set, which
returns Error::Done. That error was forwarded unchanged, so callers
saw Done (normally "no capacity") for a stream that no longer exists.

Map that case to Error::InvalidStreamState instead, matching the
behaviour of stream_recv() which already returns InvalidStreamState
for a non-existent stream. This lets applications distinguish a lack
of send capacity from an invalid stream id without an extra
stream_writable() check.

Fixes cloudflare#1695
@schiemon schiemon force-pushed the fix/stream-send-done-on-collected-stream branch from c6cad67 to d7757b2 Compare June 7, 2026 19:53
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.

Connection::stream_send() reports Err::Done for finished streams

1 participant