Overall timeout versus timeout-per-try; overall timeout cancelling waits-between-retries
See original GitHub issueHi guys, I have a doubt regarding how to apply an overall timeout and a separate timeout for each individual try. Given the below code, I would like to confirm if I’m using in the right way the policies for an overall and individual timeout.
var overalTimeoutPolicy = new IAsyncPolicy[] {
Policy.TimeoutAsync(30, TimeoutStrategy.Pessimistic),
Policy.Handle<SqlException>()
.WaitAndRetryAsync(
retryCount,
retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))),
Policy.Handle<SqlException>()
.CircuitBreakerAsync(
exceptionsAllowedBeforeBreaking,
TimeSpan.FromMinutes(1))
};
var individualTimeoutPolicy = new IAsyncPolicy[] {
Policy.Handle<SqlException>()
.WaitAndRetryAsync(
retryCount,
retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))),
Policy.TimeoutAsync(30, TimeoutStrategy.Pessimistic),
Policy.Handle<SqlException>()
.CircuitBreakerAsync(
exceptionsAllowedBeforeBreaking,
TimeSpan.FromMinutes(1))
};
Policy.Wrap(overalTimeoutPolicy).ExecuteAsync(action);
Policy.Wrap(individualTimeoutPolicy ).ExecuteAsync(action);
I appreciate in advance for your help!
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Timeouts in online versus??? : r/EA_NHL
In two separate games now I've gone to call a timeout after taking a bad icing to refresh my lines energy. Both times...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@vany0114 That looks good:
You can also do both in the same PolicyWrap: apply an overall timeout and a timeout per try. There is no barrier to using a TimeoutPolicy twice in the same PolicyWrap.
We discuss this in more depth, and show the flow through a PolicyWrap of this type, in the diagram in this part of the PolicyWrap wiki
Yes. If waits-and-retries inside a TimeoutPolicy mean the overall execution would take longer than the timeout allows, the timeout will time out the execution.
Specifically for the wait phase: both
TimeoutStrategy.Optimistic
andTimeoutStrategy.Pessimistic
have the power to cancel a WaitAndRetry policy during the wait-before-retrying phase.