async/client: Fix unary request timeout cleanup - #318
Open
Tim-Zhang wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes async unary request timeout semantics so a single absolute deadline applies across outbound queue admission, socket write, and response wait, while also ensuring stream registrations are cleaned up on timeout/cancellation and writer failures propagate correctly.
Changes:
- Add per-message control metadata (deadline + cancellation detection) and use it to discard expired/cancelled queued requests and to close the connection if a write is interrupted mid-frame.
- Apply an absolute deadline to both outbound queue admission and response waiting for unary
Client::request, with RAII cleanup for stream registrations. - Refactor the connection writer task to return a
Resultand add regression tests covering queue saturation, expired queued requests, and cancellation during write.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/asynchronous/stream.rs | Introduces MessageControl (deadline + cancellation) attached to outbound SendingMessages. |
| src/asynchronous/server.rs | Updates ReaderDelegate::disconnect signature to match the new connection contract. |
| src/asynchronous/connection.rs | Refactors writer loop to enforce deadlines/cancellation during write, discard expired queued messages, and propagate writer errors to the connection runner. |
| src/asynchronous/client.rs | Applies an absolute deadline across unary request send + receive and adds RAII stream-registration cleanup; wires in tests module. |
| src/asynchronous/client_tests.rs | Adds focused async regression tests for deadline coverage, stream cleanup, and connection closure on cancelled in-progress writes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Use one deadline while waiting for both the outbound queue and the response. Remove stream registrations when requests time out or are cancelled. Discard requests that expire before writing. Close the connection when a timeout or cancellation interrupts an in-progress write because the frame may be incomplete. Return writer failures through the task result. Add regression tests for full queues, response cleanup, queued request timeout errors, and cancellation during writes. Fixes: #317 Signed-off-by: Tim Zhang <tim@hyper.sh>
Tim-Zhang
force-pushed
the
fix-317-async-request-timeout
branch
from
August 10, 2026 13:28
bf03365 to
ce76f36
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/asynchronous/client.rs:127
- The new absolute-deadline logic is only applied to
Client::request(unary).Client::new_streamand streaming_send/StreamSender::{send,close_send}still enqueueSendingMessage::new(...)without any deadline/cancellation control and can still block indefinitely on a full outbound queue or a stuck writer, which is explicitly called out in #317. If this PR is meant to close #317 ("Fixes #317"), the same deadline mechanism should be plumbed through streaming paths and covered by regression tests; otherwise the PR description/issue linkage should be adjusted.
let sending_msg = SendingMessage::new_with_control(msg, control);
let send_result = if let Some(deadline) = deadline {
timeout_at(deadline, self.req_tx.send(sending_msg))
.await
.map_err(|_| request_timeout_error())?
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.
Summary
Root cause
The previous timeout only covered waiting for the response after the request entered the outbound queue. A request could therefore outlive its timeout while the queue or socket was blocked, and timed-out or cancelled requests could leave stream registrations behind.
Validation
cargo +1.95.0 test --features asynccargo +1.95.0 clippy --all-targets --features async -- -D warningscargo +1.95.0 fmt --all --checkgit diff --checkFixes #317