Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RetryAfter to BrokenCircuitException. #2324

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DL444
Copy link

@DL444 DL444 commented Oct 2, 2024

Pull Request

The issue or feature being addressed

Closes #2284

Details on the issue fix or feature implementation

This PR adds RetryAfter property to BrokenCircuitException to indicate time of possible circuit closure.

The implementation stores the time span from the time when the exception is thrown to the time when the circuit breaker should enter half-open state. This can cause inaccuracy if the exception is stowed and consumed at a later time, as the value would become stale. This route is chosen over storing the time of circuit closure because it

  • Maintains API consistency with RateLimiterRejectedException, another derived type of ExecutionRejectedException, whose RetryAfter was already defined to return TimeSpan.
  • Avoids performing time computation in the exception.
  • Avoids demonstrating inconsistent behavior when the value is observed multiple times.

Tests are expanded to cover the new APIs. Specific test policy proposed and implemented:

  • Direct tests against the exception types (BrokenCircuitExceptionTests, IsolatedCircuitExceptionTests) are expanded to cover the new API;
  • Issue tests are kept as-is because they are supposed to focus on the specific relevant issues.
  • Each specs test category (CircuitBreakerSpecs, CircuitBreakerAsyncSpecs, AdvancedCircuitBreakerSpecs, AdvancedCircuitBreakerAsyncSpecs, CircuitBreakerTResultSpecs, CircuitBreakerTResultMixedResultExceptionSpecs, CircuitBreakerTResultAsyncSpecs) implements one test for the value of the new RetryAfter property.
  • All other reference sites of the exception in specs tests confirm nullity of the property.

Let me know if either the implementation or the tests need rework.

It is also observed that BrokenCircuitException supports binary serialization on .NET Framework. I'm unfortunately not familiar with its details, and as a deprecated technology, information about it online is scarce. I'm not sure if this change would have any negative implications from a compatibility standpoint.

Confirm the following

  • I started this PR by branching from the head of the default branch
  • I have targeted the PR to merge into the default branch
  • I have included unit tests for the issue/feature
  • I have successfully run a local build

@DL444 DL444 changed the title Add RetryAfter to BrokenCircuitException. Add RetryAfter to BrokenCircuitException. Oct 2, 2024
Copy link

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.

Project coverage is 85.36%. Comparing base (74ac188) to head (8ede4af).

Files with missing lines Patch % Lines
...y/CircuitBreaker/BrokenCircuitException.TResult.cs 33.33% 2 Missing ⚠️
src/Polly/CircuitBreaker/CircuitStateController.cs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2324      +/-   ##
==========================================
- Coverage   85.39%   85.36%   -0.03%     
==========================================
  Files         313      313              
  Lines        7461     7470       +9     
  Branches     1126     1126              
==========================================
+ Hits         6371     6377       +6     
- Misses        745      748       +3     
  Partials      345      345              
Flag Coverage Δ
linux 85.34% <78.57%> (-0.03%) ⬇️
macos 85.34% <78.57%> (-0.05%) ⬇️
windows 85.34% <78.57%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@martintmk
Copy link
Contributor

I would keep this feature to Polly.Core only as the Polly V7 should be limited to bug fixes only. Wdyt @martincostello, @peter-csala ?

@peter-csala
Copy link
Contributor

I would keep this feature to Polly.Core only as the Polly V7 should be limited to bug fixes only. Wdyt @martincostello, @peter-csala ?

Yes, that's my understand as well. Your implementation should be limited to V8 only.

@peter-csala
Copy link
Contributor

Also, please don't forget to update the documentation as well: https://github.com/App-vNext/Polly/blob/main/docs/strategies/circuit-breaker.md

Copy link
Member

@martincostello martincostello left a comment

Choose a reason for hiding this comment

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

I agree, we should just make this change to Polly.Core.

@DL444 DL444 force-pushed the dev/dl/circuit-breaker-retry-after branch from 16dd9ad to 29f6e84 Compare October 3, 2024 17:55
@DL444
Copy link
Author

DL444 commented Oct 3, 2024

The source branch is rebased, revised, and force-pushed to incorporate the following requested changes:

  • Reverts all changes made to Polly and Polly.Specs projects as new features are no longer accepted for them.
  • Expands relevant documentations to cover the new feature.
  • Addresses miscellaneous code review comments.

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.

[Feature request]: Indicate time of possible circuit closure in BrokenCircuitException
4 participants