Skip to content

feat(transport): introduce stream I/O timeouts - #1518

Draft
rvolosatovs wants to merge 5 commits into
mainfrom
feat/transport-io-timeout
Draft

rvolosatovs wants to merge 5 commits into
mainfrom
feat/transport-io-timeout

Conversation

@rvolosatovs

Copy link
Copy Markdown
Member

closes #1045

Add an optional timeout to `frame::Incoming` and `frame::Outgoing`,
configured via `with_timeout` and inherited by sub-streams returned by
`index`. When set, a read that does not make progress within the
timeout fails with `ErrorKind::TimedOut` instead of pending forever,
which lets peers drop invocations whose counterpart stops sending data,
e.g. a client that sends fewer parameter bytes than the function
signature requires and then keeps the stream open.

`Outgoing` writes are buffered in a channel drained by a detached egress
task, so the write timeout is applied there: egress fails if the
underlying connection does not accept any data within the timeout, the
result is passed to `on_egress` and subsequent writes, flushes and
shutdowns on the stream surface the same error. A peer that stops
reading from the connection therefore causes the connection to be
released, instead of blocking it forever. The timeout is shared with the
egress task through a slot that also holds its waker, so a timeout
configured after the writer has already stalled still arms a deadline.

The QUIC and WebTransport `on_egress` handlers reset the send stream
when egress fails, so that waiting for the peer to stop the stream
resolves and the peer observes the failure.

Assisted-by: claude:claude-fable-5-1
Add `invoke::IoTimeout` and `invoke::IoTimeoutOwned` wrappers, which
apply a read and write timeout to the `Incoming` and `Outgoing` streams
returned by `Invoke::invoke`, so that an invocation errors instead of
hanging when the server stops responding mid-invocation.

This is kept separate from `InvokeExt::timeout`, which still only
bounds the `Invoke::invoke` call, since an I/O timeout also bounds the
handler's time to first result byte and applies to async sub-streams,
which may legitimately outlive the invocation and idle for longer.

Assisted-by: claude:claude-fable-5-1
Add `serve::IoTimeout` and `serve::IoTimeoutOwned` wrappers, mirroring
the `invoke` ones, which apply a read and write timeout to the
`Incoming` and `Outgoing` streams of every accepted invocation. A client
that sends fewer parameter bytes than the served function expects and
then keeps the connection open previously left the server-side decoder
pending forever (#1045); with a timeout the
invocation now fails with `ErrorKind::TimedOut` and its resources are
released. Likewise, a client that stops reading results no longer
blocks the connection forever.

Assisted-by: claude:claude-fable-5-1
@rvolosatovs
rvolosatovs force-pushed the feat/transport-io-timeout branch from 2d1620e to e6d507d Compare October 8, 2026 14:09
Bound the `Invoke::invoke` call itself in `invoke::IoTimeout`, so that
the synchronous parameter write, which happens before the `Outgoing`
stream exists, can no longer hang forever when the server stops reading;
add a test covering that path.

Return from the QUIC and WebTransport `on_egress` handlers right after
resetting the send stream on failure, since quinn never wakes
`stopped()` for a locally reset stream and the task would otherwise
linger until the connection closed. Name the WebTransport stream error
codes.

Only clone the egress waker when it changed.

Document that the read timeout bounds idle gaps, including the time to
first byte, that `Incoming::with_timeout` is armed lazily and only
inherited by sub-streams indexed afterwards, and that `Outgoing` flushes
and shutdowns only report a write timeout that already occurred.

Assisted-by: claude:claude-fable-5-1
Clear the `Incoming` read deadline once it fires, so that a read
retried after `ErrorKind::TimedOut` gets a fresh window instead of
failing immediately on the expired timer forever; add a test.

Only report write timeouts from `Outgoing` flushes and shutdowns, so
that other background write errors, e.g. a peer that stopped reading
after receiving everything it needed, no longer turn a previously
successful flush into an error.

Reuse `invoke::Timeout` in `invoke::IoTimeout` instead of duplicating
it, and use `core::error::Error` in `egress_error`.

Document that dropping a pending read does not clear the read deadline,
and that `ServeExt::io_timeout` does not bound reads a transport does
before yielding an invocation, such as the header read in
`frame::Server::accept`.

Assisted-by: claude:claude-opus-5-5
@rvolosatovs
rvolosatovs force-pushed the feat/transport-io-timeout branch from abaca76 to 7ee06eb Compare October 8, 2026 14:59

This branch has not been deployed

No deployments
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.

1 participant