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

Merged

Conversation

DL444
Copy link
Contributor

@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

All modified and coverable lines are covered by tests ✅

Project coverage is 85.40%. Comparing base (439cf15) to head (9a93845).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2324      +/-   ##
==========================================
+ Coverage   85.39%   85.40%   +0.01%     
==========================================
  Files         313      313              
  Lines        7461     7467       +6     
  Branches     1126     1126              
==========================================
+ Hits         6371     6377       +6     
  Misses        745      745              
  Partials      345      345              
Flag Coverage Δ
linux 85.40% <100.00%> (+0.01%) ⬆️
macos 85.37% <100.00%> (+0.01%) ⬆️
windows 85.40% <100.00%> (+0.01%) ⬆️

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
Contributor 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.

@DL444
Copy link
Contributor Author

DL444 commented Oct 4, 2024

New commits are added to:

  • Implement binary serialization support for the new property.
  • Refactor exception constructor tests to improve readability.

@DL444 DL444 force-pushed the dev/dl/circuit-breaker-retry-after branch from 6fb3dff to b3e0aaa Compare October 4, 2024 16:26
@DL444 DL444 force-pushed the dev/dl/circuit-breaker-retry-after branch from b3e0aaa to 9a93845 Compare October 5, 2024 17:06
@martincostello martincostello merged commit faaa79d into App-vNext:main Oct 5, 2024
18 checks passed
@martincostello martincostello added this to the v8.5.0 milestone Oct 5, 2024
Copy link
Contributor

Thanks for your contribution @DL444 - the changes from this pull request have been published as part of version 8.5.0 📦, which is now available from NuGet.org 🚀

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