Skip to content

async/client: Fix unary request timeout cleanup - #318

Open
Tim-Zhang wants to merge 1 commit into
masterfrom
fix-317-async-request-timeout
Open

async/client: Fix unary request timeout cleanup#318
Tim-Zhang wants to merge 1 commit into
masterfrom
fix-317-async-request-timeout

Conversation

@Tim-Zhang

Copy link
Copy Markdown
Member

Summary

  • apply one absolute deadline while a unary request waits for the outbound queue and its response
  • remove stream registrations when requests time out or their futures are cancelled
  • discard expired queued requests before writing, while closing connections interrupted during a write to avoid reusing a potentially partial frame
  • propagate writer failures through the writer task result and add focused regression tests

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 async
  • cargo +1.95.0 clippy --all-targets --features async -- -D warnings
  • cargo +1.95.0 fmt --all --check
  • git diff --check

Fixes #317

@Tim-Zhang
Tim-Zhang marked this pull request as ready for review August 6, 2026 10:52
@Tim-Zhang
Tim-Zhang requested a lite review from Copilot August 10, 2026 13:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Result and 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.

Comment thread src/asynchronous/connection.rs
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
Tim-Zhang force-pushed the fix-317-async-request-timeout branch from bf03365 to ce76f36 Compare August 10, 2026 13:28
@Tim-Zhang
Tim-Zhang requested a lite review from Copilot August 10, 2026 13:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_stream and streaming _send/StreamSender::{send,close_send} still enqueue SendingMessage::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())?

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.

async client: request timeout does not cover outbound queue and socket write

2 participants