Fix #4434: only count caller-initiated cancellations as canceled requests#4592
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes IceRpc.Metrics cancellation classification so only caller-initiated cancellations increment canceled-requests, while other OperationCanceledException cases (deadline/abort/linked tokens, etc.) are treated as failures and increment failed-requests, addressing #4434.
Changes:
- Tightened
OperationCanceledExceptionhandling inMetricsInterceptorandMetricsMiddlewareby filtering onexception.CancellationToken == cancellationToken. - Updated existing cancellation tests to use a real
CancellationTokenSourceso they validate the intended token-matching behavior. - Added regression tests ensuring an
OperationCanceledExceptionwith an unrelated token incrementsfailed-requests(notcanceled-requests).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/IceRpc.Metrics/MetricsMiddleware.cs | Counts cancellations only when the thrown OCE carries the same dispatch token. |
| src/IceRpc.Metrics/MetricsInterceptor.cs | Counts cancellations only when the thrown OCE carries the same invocation token. |
| tests/IceRpc.Metrics.Tests/MetricsMiddlewareTests.cs | Fixes cancellation test token usage and adds regression coverage for unrelated-token OCE. |
| tests/IceRpc.Metrics.Tests/MetricsInterceptorTests.cs | Fixes cancellation test token usage and adds regression coverage for unrelated-token OCE. |
pepone
approved these changes
May 8, 2026
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
externl
approved these changes
May 8, 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.
Fixes #4434.
Tighten the
OperationCanceledExceptioncatch clauses inMetricsInterceptorandMetricsMiddlewarewith awhen (exception.CancellationToken == cancellationToken)filter, so only caller-initiated cancellations are counted ascanceled-requests. Other OCEs (deadline timeouts, transport aborts, linked sources from other interceptors, etc.) now fall through to the failure handler and are counted asfailed-requests.Also updated the existing canceled tests to use a real
CancellationTokenSource(the previous tests passed by accident since both tokens wereNone), and added regression tests asserting that an OCE carrying an unrelated token incrementsfailed-requests, notcanceled-requests.