question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Behaviour of ExecuteAndCapture with PolicyWrap and with Fallback

See original GitHub issue

I’m wrapping a retry policy in timeout policy. The action returns null so I want to retry.

With retry policy alone, I get result.Outcome as Failure as expected. But with timeout policy, it is Successful with result.Result as null. Shouldn’t it also be a Failure?

If the action throws, then I see Failure for both retry and timeout policies.

class Holder
{
	public bool done;
	public Holder holder;
}

[Test]
public async Task Polly_Result_Outcome_Should_Be_Failure()
{
	Policy<Holder> retry = Policy
				   .Handle<Exception>()
				   .OrResult<Holder>(h =>
				   {
					   var flag = !(h?.holder?.done) ?? true;
					   return flag;
				   })
				   .WaitAndRetryAsync(
					   2,
					   retryAttempt => TimeSpan.FromMilliseconds(1000));
	var timeout = Policy
				  .TimeoutAsync(10)
				  .WrapAsync(retry);
	var result = await timeout.ExecuteAndCaptureAsync(async (ct) =>
	{
		ct.ThrowIfCancellationRequested();
		//throw new Exception();
		return await Task.FromResult((Holder)null);
	}, CancellationToken.None)
		.ConfigureAwait(false);
	if (result.Outcome != OutcomeType.Successful)
	{
		// retry policy comes here as expected
		Assert.Pass();
	}
	if (result.Result == null)
	{
		// timeout policy comes here
		// why is Outcome not OutcomeType.Failure just like retry policy?
	}
	Assert.Fail();
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
reisenbergercommented, Jul 12, 2018

Closing this as I think we’re done here, and we’ve updated the wiki to cover this more precisely. However, if you do need anything else, please re-open the issue or start a fresh one. Also updated the title of the issue for future discoverability. Thanks for your great question!

0reactions
reisenbergercommented, Jul 6, 2018

@rmandvikar Thanks again for your great example which highlights these important points! We’ve updated the documentation for both PolicyWrap and Fallback to make this clearer.

Let us know if there is anything else we can help with.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Polly: wrap AsyncFallbackPolicy<TResult> with ...
A non-generic AsyncFallbackPolicy cannot participate in an execution asynchronously returning bool for the reasons stated in the error message: ...
Read more >
Building Polly Fallbacks for Resilient .NET Service-to- ...
It will guide you in using the Fallback policy to handle failures you ... the response and determines if its behavior clause should...
Read more >
Retry and fallback policies in C# with Polly - Jacob Duijzer
In this blog I will try to explain how one can create clean and effective policies to retry API calls and have fallbacks...
Read more >
NET Core Polly (How it Works for Developers)
Fallback policy is used to provide a substitute value or behavior in the event ... Polly will try to execute the underlying delegate...
Read more >
Resilience APIs to Transient Faults using Polly - NET Nakama
In our use case, we need to execute an action in our Web API (GetData) ... Combination of Multiple Strategies, Policy Wrap, Different...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found