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

Clearing out the only 1805 violation using the method listed here: ht… #2032

Closed
wants to merge 1 commit into from

Conversation

cbredlow
Copy link

@cbredlow cbredlow commented Mar 26, 2024

…tps://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1805#how-to-fix-violations

Pull Request

The issue or feature being addressed

Addressing the CA1805 as a part of issue 1290

Details on the issue fix or feature implementation

Removed the NoWarn for CA1805, and changes the spinner to be static and have a lambda for the default value, as suggested here: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1805#how-to-fix-violations

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

@cbredlow
Copy link
Author

@dotnet-policy-service agree

Copy link

codecov bot commented Mar 26, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 83.66%. Comparing base (785c482) to head (37d201e).

Files Patch % Lines
.../Polly/RateLimit/LockFreeTokenBucketRateLimiter.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2032      +/-   ##
==========================================
- Coverage   83.70%   83.66%   -0.04%     
==========================================
  Files         312      312              
  Lines        7105     7106       +1     
  Branches     1054     1054              
==========================================
- Hits         5947     5945       -2     
- Misses        788      790       +2     
- Partials      370      371       +1     
Flag Coverage Δ
linux 83.66% <0.00%> (-0.04%) ⬇️
macos 83.66% <0.00%> (-0.02%) ⬇️
windows 83.66% <0.00%> (-0.02%) ⬇️

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.

@@ -15,7 +15,7 @@ internal sealed class LockFreeTokenBucketRateLimiter : IRateLimiter
private long addNextTokenAtTicks;

#if !NETSTANDARD2_0
private SpinWait spinner = default;
private static SpinWait spinner => default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I don't believe this is the correct change to make here.

Making this a static property means that each access to the spinner effectively resets the internal state it has as all usage of it now gets a fresh value instead of the state being maintained for the lifetime of an instance of the rate limiter.

Either instead of default we should change the original code to use new(), and if that still raises warnings, then we should just explicitly suppress the CA1805 warning instead.

@cbredlow cbredlow marked this pull request as draft March 27, 2024 03:51
@martincostello
Copy link
Member

I'm going to close this due to activity. If you'd like to continue with this contribution, please open a new PR that addresses the comment here: #2032 (comment)

@cbredlow cbredlow deleted the cbredlow/CA1805_cleanup branch April 29, 2024 16:33
@martincostello martincostello mentioned this pull request Jul 21, 2024
5 tasks
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.

2 participants