Skip to content

Retry only known-transient exceptions in the resilience pipeline#395

Merged
ptr727 merged 1 commit into
developfrom
feature/narrow-transient-retry
Jul 10, 2026
Merged

Retry only known-transient exceptions in the resilience pipeline#395
ptr727 merged 1 commit into
developfrom
feature/narrow-transient-retry

Conversation

@ptr727

@ptr727 ptr727 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

Narrows HttpClientFactory.IsTransientFailure so the retry pipeline handles only known-transient failures instead of defaulting unknown exceptions to transient (_ => true). Retrying arbitrary exceptions - including programming errors like ArgumentException/InvalidOperationException - masks bugs and adds needless load.

Now transient means:

  • Transient HTTP status (408, 429, >= 500).
  • A request timeout (a cancellation carrying an inner TimeoutException).
  • A network/IO error (HttpRequestException, IOException).

Everything else - caller cancellation, an open circuit, and any other exception - is not retried. This aligns with the Microsoft.Extensions.Http.Resilience transient defaults.

Tests

Adds two deterministic mocked tests: a network exception is retried; a non-transient (InvalidOperationException) is not.

Verification

  • dotnet build - 0 warnings / 0 errors.
  • dotnet test - 151 passed (+2).
  • dotnet format style --verify-no-changes clean.

Addresses a Copilot finding on the develop->main release PR (#394).

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 10, 2026 19:06
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.37%. Comparing base (c3c7843) to head (c85feac).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #395      +/-   ##
===========================================
+ Coverage    46.20%   46.37%   +0.17%     
===========================================
  Files           13       13              
  Lines         1160     1160              
  Branches       107      107              
===========================================
+ Hits           536      538       +2     
+ Misses         593      592       -1     
+ Partials        31       30       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Pull request overview

This PR tightens HttpClientFactory.IsTransientFailure so the resilience retry strategy only retries known-transient failures (specific HTTP status codes, timeout-as-cancellation-with-inner-TimeoutException, and network/IO exceptions), and adds tests to ensure network exceptions are retried while programming errors are not.

Changes:

  • Narrow transient-exception handling in HttpClientFactory.IsTransientFailure to avoid retrying unknown/programming exceptions.
  • Add deterministic resilience tests for retrying HttpRequestException and not retrying InvalidOperationException.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Utilities/HttpClientFactory.cs Restricts exception-based transient detection to timeout-cancellation and network/IO exceptions.
UtilitiesTests/HttpClientFactoryResilienceTests.cs Adds tests asserting retry behavior for network vs. non-transient exceptions.

Comment thread Utilities/HttpClientFactory.cs
@ptr727
ptr727 merged commit 2b52e73 into develop Jul 10, 2026
12 checks passed
@ptr727
ptr727 deleted the feature/narrow-transient-retry branch July 10, 2026 19:08
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.

2 participants