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.

In async PolicyWrap executions, Context.PolicyKey and Context.PolicyWrapKey may reset to outer values in the PolicyWrap too early

See original GitHub issue

Summary:

Policykey Context property is null when its passed to onRetry delegate when using WaitAndRetryAsync + ExecuteAsync.

Perhaps i’m missing something here, although i’m not able to reproduce if I switch to a synchronous policy.

Expected behavior: after setting PoliyKey when creating policy, its then set on the Context object passed to onRetry delegate.

PS C:\Users\hamish.rose\Desktop\test> dotnet run
In on retry. PolicyKey: test, OperationKey: ExecutingMethod

Actual behaviour: PolicyKey is null on Context object passed to onRetry delegate, even though its set on the policy.

PS C:\Users\hamish.rose\Desktop\test> dotnet run
In on retry. PolicyKey: , OperationKey: ExecutingMethod

Steps / Code to reproduce the problem:

using System;
using System.Threading.Tasks;
using Polly;
using Polly.Retry;

namespace test
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var policy = Policy.Handle<Exception>()
                  .WaitAndRetryAsync(
                  1,
                  (x, y) => TimeSpan.FromSeconds(5),
                  (ex, timespan, context) => Console.WriteLine($"In on retry. PolicyKey: {context.PolicyKey}, OperationKey: {context.OperationKey}"))
                  .WithPolicyKey("test") as RetryPolicy;

            await policy.ExecuteAsync(async context => await Task.Run(() => throw new Exception()), new Context("ExecutingMethod"));
        }
    }
}

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
reisenbergercommented, Nov 11, 2018

Fix merged to master. Will be live as soon as v6.1.1 is released to nuget

0reactions
reisenbergercommented, Oct 7, 2018

@hamish-rose Thanks for the confirmation!

Read more comments on GitHub >

github_iconTop Results From Across the Web

v6.1.1 Milestone
In async PolicyWrap executions, Context.PolicyKey and Context.PolicyWrapKey may reset to outer values in the PolicyWrap too early bug ready.
Read more >
Polly - Please use asynchronous-defined policies when ...
You are combining synchronous and asynchronous execution here, hence the error message. This is because of the last line of code:
Read more >
Using Execution Context in Polly
RetryAsync (1, onRetryAsync: async (e, i) => await AuthHelper.RefreshAuthorization(httpClient)); var httpResponseMessage = await ...
Read more >
Polly 7.2.4
Async continuations and retries by default do not run on a captured synchronization context. To change this, use . ExecuteAsync(...) overloads taking a...
Read more >
Authoring a proactive Polly policy (Custom policies Part II)
In this article we'll build our first custom Polly policy: a proactive Policy to capture execution timings. Polly polices fall into two ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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