Skip to content

Fixes CA2213 issues on NuGet client repo#4812

Merged
dominoFire merged 16 commits intodevfrom
dev-dominofire-fixca2213
Oct 21, 2022
Merged

Fixes CA2213 issues on NuGet client repo#4812
dominoFire merged 16 commits intodevfrom
dev-dominofire-fixca2213

Conversation

@dominoFire
Copy link
Contributor

@dominoFire dominoFire commented Sep 20, 2022

Bug

Fixes: NuGet/Home#12116

Regression? Last working version: N/A

Description

  • Fixes CA2213 rule by calling Dispose() on internal HTTP client on HttpSourceAuthenticationHandler class
  • Fixes CA2213 rule in test code
  • Added an inline suppression in test code, since Analyzer thinks the rule is not solved.
  • Added unit tests for HttpSourceAuthenticationHandler.Dispose()
  • Throw ObjectDisposedException when calling SendAsync() on HttpSourceAuthenticationHandler disposed object
  • Added backslash dir separator in project files to fix issues in my devbox when using a NuGetPackageRoot without trailing backslash char.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added: Added 3 tests for product code
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A: No product change

@dominoFire dominoFire marked this pull request as ready for review September 20, 2022 04:06
@dominoFire dominoFire requested a review from a team as a code owner September 20, 2022 04:06
Copy link
Contributor

@donnie-msft donnie-msft left a comment

Choose a reason for hiding this comment

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

Thanks for jumping on this! I just have some questions about testing strategy...

HttpHandlerResourceV3.CredentialsSuccessfullyUsed?.Invoke(uri, credentials);
}

protected override void Dispose(bool disposing)
Copy link
Member

Choose a reason for hiding this comment

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

Do we ever call dispose on the handler?

The thing about the dispose pattern is that it needs to be implement all the way up the stack. Are we doing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems no.

HttpSourceAuthenticationHandler objects are created inside HttpHandlerResourceV3Provider.TryCreate() method. Objects returned by this method are INuGetResource-based. This interface does not implement any IDisposable-based interfaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In short words: we don't call dispose on this class in NuGet.Client source code. We are now just being good citizens by implementing Dispose.

Copy link
Contributor

@erdembayar erdembayar Oct 19, 2022

Choose a reason for hiding this comment

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

How about we just accept this dispose changes as it's? But create/link another follows up issue for implementing dispose pattern all the way up the stack, fixing that part shouldn't be high priority for now.
Or just suppress with reason why it doesn't add any value by doing so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm looking forward to merging this PR. Added follow up issue to use IDisposable pattern in NuGet protocol code. NuGet/Home#12176

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we call GC.SuppressFinalize(this); in dispose? We're doing it for another dispose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not here, that should be called in Dispose() method (without arguments) of base class

Copy link
Contributor

@erdembayar erdembayar Oct 20, 2022

Choose a reason for hiding this comment

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

Not here, that should be called in Dispose() method (without arguments) of base class

Sure, thank you for clarifying.

zivkan
zivkan previously approved these changes Sep 26, 2022
@dominoFire
Copy link
Contributor Author

dominoFire commented Oct 5, 2022

Team review: Add tests that dispose multiple times to verify nothing else throws exceptions.

@ghost ghost added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Oct 12, 2022
@ghost
Copy link

ghost commented Oct 12, 2022

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@dominoFire dominoFire force-pushed the dev-dominofire-fixca2213 branch from 3467f70 to 714a6b6 Compare October 18, 2022 20:16
@ghost ghost removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Oct 18, 2022
@dominoFire dominoFire requested a review from erdembayar October 20, 2022 08:25
Copy link
Contributor

@erdembayar erdembayar left a comment

Choose a reason for hiding this comment

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

I believe we address 1 problem at the time, so this is good enough for merging.

@dominoFire dominoFire merged commit d1620d3 into dev Oct 21, 2022
@dominoFire dominoFire deleted the dev-dominofire-fixca2213 branch October 21, 2022 00:47
kartheekp-ms pushed a commit that referenced this pull request Nov 10, 2022
Fixes NuGet/Home#12116

Fixes CA2213 in HttpSourceAuthenticationHandler and in test code. Left 1 CA2213 suppression due to a Roslyn analyzer bug linked in the suppression code.
erdembayar pushed a commit that referenced this pull request Jan 24, 2023
Fixes NuGet/Home#12116

Fixes CA2213 in HttpSourceAuthenticationHandler and in test code. Left 1 CA2213 suppression due to a Roslyn analyzer bug linked in the suppression code.
erdembayar pushed a commit that referenced this pull request Jan 24, 2023
Fixes NuGet/Home#12116

Fixes CA2213 in HttpSourceAuthenticationHandler and in test code. Left 1 CA2213 suppression due to a Roslyn analyzer bug linked in the suppression code.
erdembayar pushed a commit that referenced this pull request Jan 24, 2023
Fixes NuGet/Home#12116

Fixes CA2213 in HttpSourceAuthenticationHandler and in test code. Left 1 CA2213 suppression due to a Roslyn analyzer bug linked in the suppression code.
erdembayar pushed a commit that referenced this pull request Jan 24, 2023
Fixes NuGet/Home#12116

Fixes CA2213 in HttpSourceAuthenticationHandler and in test code. Left 1 CA2213 suppression due to a Roslyn analyzer bug linked in the suppression code.
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.

[Bug]: Address CA2213 warnings

6 participants