Add JsonRpc outbound request timeout#1471
Merged
Merged
Conversation
Add a JsonRpc-wide OutboundRequestTimeout that applies to response-expected outbound calls, turns timeout-origin failures into TimeoutException, preserves caller cancellation tokens, and exercises the behavior across direct, proxy, and cancellation-strategy tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a connection-wide outbound invocation timeout (JsonRpc.OutboundRequestTimeout) so both direct Invoke* APIs and proxy-generated calls can be bounded without per-call linked CancellationTokenSource management, with updated exception behavior and accompanying tests.
Changes:
- Introduces
JsonRpc.OutboundRequestTimeout(nullable, disabled by default) with validation and documentation. - Applies the timeout in the shared outbound invoke path and translates timeout-triggered cancellation to
TimeoutException(with invariant message text containingnameof(JsonRpc.OutboundRequestTimeout)). - Adds coverage for timeout behavior across direct invokes, proxies, notifications, and cancellation-strategy interactions.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/StreamJsonRpc.Tests/JsonRpcTests.cs | Adds direct invoke tests for outbound timeout behavior and precedence vs caller cancellation. |
| test/StreamJsonRpc.Tests/JsonRpcProxyGenerationTests.cs | Adds a proxy-call test verifying the JsonRpc-level outbound timeout is honored. |
| test/StreamJsonRpc.Tests/JsonRpcClient20InteropTests.cs | Adds a test ensuring notifications ignore outbound timeout. |
| test/StreamJsonRpc.Tests/CustomCancellationStrategyTests.cs | Adds a test verifying timeout-triggered cancellation still routes through cancellation strategy behavior. |
| src/StreamJsonRpc/Resources.resx | Adds resource strings for positive TimeSpan validation and timeout exception messaging. |
| src/StreamJsonRpc/JsonRpc.cs | Adds OutboundRequestTimeout and integrates timeout cancellation + exception shaping into outbound invoke pipeline. |
Translate timeout-driven send-path cancellations into TimeoutException, align most timeout tests with ExpectedTimeout, and keep the custom cancellation-strategy timeout at 100ms because the larger shared timeout hangs on net472 in that scenario. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
RyanToth3
approved these changes
Jun 23, 2026
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.
Why
Issue #1443 asks for a connection-wide way to bound outbound RPC calls instead of requiring each call site to create and dispose a linked
CancellationTokenSourcemanually.Fixes #1443
What changed
JsonRpc.OutboundRequestTimeoutas a nullable, disabled-by-default setting for response-expected outbound calls.Invoke*APIs and proxy-generated calls behave the same way.TimeoutExceptionand includenameof(JsonRpc.OutboundRequestTimeout)in the message so tests can assert on invariant text instead of localized English.OperationCanceledExceptionnow escapes with the caller's original token rather than an internal linked token.$/cancelRequestis sent even though the caller stops waiting immediately.Notes
The timeout only stops waiting on the client side. The server may still be processing the request, and the PR keeps that behavior explicit in the thrown timeout message.
Testing
dotnet build -c Releasenet9.0,net8.0, andnet472net9.0withTestCategory=FailsInCloudTestexcluded