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

v 7.2.2 uses 7.0.0 assembly #852

Closed
ruifrvaz opened this issue May 5, 2021 · 4 comments
Closed

v 7.2.2 uses 7.0.0 assembly #852

ruifrvaz opened this issue May 5, 2021 · 4 comments
Labels

Comments

@ruifrvaz
Copy link

ruifrvaz commented May 5, 2021

Summary:
It seems that v7.2.2 as installed in vs nuget package manager contains the 7.0.0 dll. It doesn't seem to be an incorrect assembly version number but the entire assembly is the 7.0.0. I have tried using WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, DelegateResult, Context, TimeSpan> sleepDurationProvider) which should be present in 7.2.2, but it is not.

I am using netcoreapp3.1 framework and package reference is



Expected behavior:
7.2.2 version uses 7.2.2 assembly.



Actual behaviour:
7.2.2 version uses 7.0.0 assembly.



Steps / Code to reproduce the problem:
Install polly 7.2.2. and check dll in nuget package located in ".nuget\packages\polly\7.2.2\lib\netstandard2.0"

@martincostello
Copy link
Member

Hello - viewing the NuGet package in NuGet Package Explorer shows me the following:

image

As you can see from the screenshot the assembly version is 7.0.0, but the other version numbers are 7.2.2.

You can also see the Git SHA used to build it, which corresponds to the commit associated with the tag for version 7.2.2. This then correlates back to the AppVeyor build that produced the assembly and the NuGet package, whose artifact is binarily identical to the one in NuGet except for the signature added by the NuGet gallery after the package was uploaded for publishing.

This difference in version numbers is in keeping with the recommendations for versioning for .NET libraries published by Microsoft. The relevant part of the documentation for the assembly version is quoted below:

✔️ CONSIDER only including a major version in the AssemblyVersion.
e.g. Library 1.0 and Library 1.0.1 both have an AssemblyVersion of 1.0.0.0, while Library 2.0 has AssemblyVersion of 2.0.0.0. When the assembly version changes less often, it reduces binding redirects.

This is why the Assembly Version is 7.0.0.0, but the other versions are 7.2.2.

Let me know if you have any further questions regarding versioning.

I can't find WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, DelegateResult, Context, TimeSpan> sleepDurationProvider) in the source code for 7.2.2 either, but it's not because the wrong version is in NuGet.org - what makes you think that specific overload should exist?

The closest matches I can find are:

public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, Exception, Context, TimeSpan> sleepDurationProvider, Func<Exception, int, TimeSpan, Context, Task> onRetryAsync)

and

public static AsyncRetryPolicy<TResult> WaitAndRetryAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<DelegateResult<TResult>, TimeSpan, int, Context> onRetry)

@ruifrvaz
Copy link
Author

ruifrvaz commented May 5, 2021

Hi @martincostello Thanks for the reply. I understand now why it is still using 7.0.0 as assembly version.

I was hoping that the overload would exist in 7.2.2 due to this closed issue #840.
I have found it here on the version you mentioned and i can confirm it is present in my assembly:

public static AsyncRetryPolicy<TResult> WaitAndRetryAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, int retryCount,

As it is, you can close this issue. If you have a bit more time, please read on:

I am attempting to do the same as in #414 . These examples are outdated and the wiki also points to this outdated issue (https://github.com/App-vNext/Polly/wiki/Retry#retryafter-when-the-response-specifies-how-long-to-wait).

I was hoping that that applying WaitAndRetryAsync on the PolicyBuilder would still work in 7.2.2, but the return type is now AsyncRetryPolicy.

A quick excerpt from #414 that doesn't work anymore:

var _retryAfterPolicy = Policy .HandleResult<HttpResponseMessage>(r => r?.Headers?.RetryAfter != null) .WaitAndRetryAsync( retryCount: numRetries, sleepDurationProvider: (retryCount, response, context) => getServerWaitDuration(response) );

If you can update the wiki to point to the new overload and to a more recent working example, it would be greatly helpful!

@ruifrvaz
Copy link
Author

ruifrvaz commented May 5, 2021

I have found another issue which has a potential solution #763 and is mentioned on #414. Haven't tested yet, but here is an example of how to create a policy with the expected WaitAndRetryAsync that returns an AsyncRetryPolicy:

var retryPolicy = Policy
                .HandleResult<HttpResponseMessage>(r => r?.Headers?.RetryAfter != null)
                .WaitAndRetryAsync(retryCount: someRetryCount,
                                    sleepDurationProvider: (retryCount, response, context) => GetServerWaitDuration(response),
                                    onRetryAsync: (response, timespan, retryCount, context) => Task.CompletedTask);

and

private TimeSpan GetServerWaitDuration(DelegateResult<HttpResponseMessage> response)
        {
            var retryAfter = response?.Result?.Headers?.RetryAfter;
            if (retryAfter == null)
                return TimeSpan.Zero;
            return retryAfter.Date.HasValue
                ? retryAfter.Date.Value - DateTime.UtcNow
                : retryAfter.Delta.GetValueOrDefault(TimeSpan.Zero);
        }

@martincostello
Copy link
Member

I've opened #853 to tackle updating the samples. Thanks for reporting the out-of-date content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants