Retry only known-transient exceptions in the resilience pipeline#395
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
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.IsTransientFailureto avoid retrying unknown/programming exceptions. - Add deterministic resilience tests for retrying
HttpRequestExceptionand not retryingInvalidOperationException.
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. |
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.
Summary
Narrows
HttpClientFactory.IsTransientFailureso the retry pipeline handles only known-transient failures instead of defaulting unknown exceptions to transient (_ => true). Retrying arbitrary exceptions - including programming errors likeArgumentException/InvalidOperationException- masks bugs and adds needless load.Now transient means:
TimeoutException).HttpRequestException,IOException).Everything else - caller cancellation, an open circuit, and any other exception - is not retried. This aligns with the
Microsoft.Extensions.Http.Resiliencetransient 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-changesclean.Addresses a Copilot finding on the develop->main release PR (#394).
🤖 Generated with Claude Code