Skip to content

Update Polly to 8.7.0 - #7742

Open
gitmln wants to merge 3 commits into
dotnet:mainfrom
gitmln:polly-retry-cancellation-issue
Open

Update Polly to 8.7.0#7742
gitmln wants to merge 3 commits into
dotnet:mainfrom
gitmln:polly-retry-cancellation-issue

Conversation

@gitmln

@gitmln gitmln commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #7741

With Polly 8.4.2 the retry strategy returns the last failed outcome instead of throwing when the caller's token is cancelled. Behind AddStandardResilienceHandler, a gRPC client that the caller cancels during an attempt ending in a retryable failure therefore reports StatusCode.Unavailable (or Unknown / Internal, depending on the failure) instead of StatusCode.Cancelled. Polly changed this in 8.5.2 (App-vNext/Polly#2456).

Two commits:

  • a test in GrpcResilienceTests for that scenario — fails on main;
  • Polly, Polly.Core, Polly.Extensions, Polly.RateLimiting and Polly.Testing to 8.7.0 — makes it pass.

The behaviour change is the fix: with a cancelled token, a retryable failure now surfaces as OperationCanceledException rather than as the outcome of the last attempt. Non-retryable outcomes are returned as before.

I used Claude Code for the investigation and to draft the test; I ran the tests myself.

Microsoft Reviewers: Open in CodeFlow

With Polly 8.4.2, a gRPC call that the caller cancels while an attempt
is in flight, and whose attempt then completes with a retryable
failure, ends with StatusCode.Unavailable instead of
StatusCode.Cancelled. The retry strategy returns the last outcome
instead of throwing when the token is cancelled; Polly changed this in
8.5.2 (App-vNext/Polly#2456).

The test fails on main and passes with the Polly packages at 8.7.0.
Bumps Polly, Polly.Core, Polly.Extensions, Polly.RateLimiting and
Polly.Testing together. 8.7.0 declares the same dependencies and
target frameworks as 8.4.2.

Makes SayHello_StandardResilience_CancelledWhileAttemptCompletes_Cancelled
pass; the remaining tests in Microsoft.Extensions.Http.Resilience.Tests
and Microsoft.Extensions.Resilience.Tests are unaffected.
@gitmln
gitmln requested review from a team as code owners September 9, 2026 10:24
Copilot AI lite review requested due to automatic review settings September 9, 2026 10:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is narrowly scoped (targeted regression test + consistent package version bump) and directly validates the intended behavioral fix.

Pull request overview

Updates the repository’s pinned Polly dependencies to address a gRPC cancellation behavior regression when using AddStandardResilienceHandler, and adds a regression test to lock in the expected StatusCode.Cancelled outcome.

Changes:

  • Added a gRPC resilience regression test covering “caller cancels while a retryable transient failure completes”.
  • Updated pinned Polly package versions (runtime + testing) to 8.7.0 to pick up the fixed cancellation behavior.
File summaries
File Description
test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/GrpcResilienceTests.cs Adds a regression test for cancellation during a retryable failure and extends client creation to allow injecting a primary handler.
eng/packages/Tests.props Bumps Polly.Testing to 8.7.0 for test dependency alignment.
eng/packages/General.props Bumps Polly, Polly.Core, Polly.Extensions, and Polly.RateLimiting to 8.7.0 to pick up the cancellation semantics fix.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@gitmln gitmln changed the title Update Polly to 8.7.0 Update Polly to 8.7.0 Sep 9, 2026
CA2000 flagged the TestHandlerStub created inline in
SayHello_StandardResilience_CancelledWhileAttemptCompletes_Cancelled.
CreateClient now takes a Func<HttpMessageHandler>, matching how the
other tests hand primary handlers to ConfigurePrimaryHttpMessageHandler.
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.

gRPC client with AddStandardResilienceHandler reports Unavailable instead of Cancelled when the caller cancels during a transient failure

2 participants