Skip to content

Fix #4434: only count caller-initiated cancellations as canceled requests#4592

Merged
bernardnormier merged 3 commits into
mainfrom
fix4434
May 8, 2026
Merged

Fix #4434: only count caller-initiated cancellations as canceled requests#4592
bernardnormier merged 3 commits into
mainfrom
fix4434

Conversation

@bernardnormier
Copy link
Copy Markdown
Member

Fixes #4434.

Tighten the OperationCanceledException catch clauses in MetricsInterceptor and MetricsMiddleware with a when (exception.CancellationToken == cancellationToken) filter, so only caller-initiated cancellations are counted as canceled-requests. Other OCEs (deadline timeouts, transport aborts, linked sources from other interceptors, etc.) now fall through to the failure handler and are counted as failed-requests.

Also updated the existing canceled tests to use a real CancellationTokenSource (the previous tests passed by accident since both tokens were None), and added regression tests asserting that an OCE carrying an unrelated token increments failed-requests, not canceled-requests.

Copy link
Copy Markdown

Copilot AI left a comment

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 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 OperationCanceledException handling in MetricsInterceptor and MetricsMiddleware by filtering on exception.CancellationToken == cancellationToken.
  • Updated existing cancellation tests to use a real CancellationTokenSource so they validate the intended token-matching behavior.
  • Added regression tests ensuring an OperationCanceledException with an unrelated token increments failed-requests (not canceled-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.

Comment thread tests/IceRpc.Metrics.Tests/MetricsMiddlewareTests.cs Fixed
Comment thread tests/IceRpc.Metrics.Tests/MetricsInterceptorTests.cs Fixed
bernardnormier and others added 2 commits May 8, 2026 09:16
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@bernardnormier bernardnormier merged commit b614072 into main May 8, 2026
12 checks passed
@bernardnormier bernardnormier deleted the fix4434 branch May 12, 2026 21:13
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.

[Audit-Medium] both components classify any OperationCanceledExceptio…

4 participants