Fix package restore cycle detection#9051
Merged
drewnoakes merged 20 commits intodotnet:mainfrom May 31, 2023
Merged
Conversation
Also remove redundant `Size` property.
Calling `Start` on a running `Stopwatch` does nothing. The prior code could start, then return early, then potentially re-enter and misrepresent the duration of the restore. Calling `Restart` ensures the value starts from zero each time and we report the correct duration.
Allows dogfooding new C# 12 features.
The previous code was storing `byte[]` as a key in a dictionary, without specifying a comparer. `byte[]` only provides reference equality by default, not structural equality. To fix this issue, we wrap the `byte[]` with a new `Hash` type that provides the appropriate hashing/equality checks for the type, makes its value immutable, and offers better type safety than the previous code.
Simplify the message and identify the problematic project.
All other types in this folder are named `PackageRestore*`. This should be no different.
There's no runtime difference here. I just find the code easier to read this way.
This consolidates all cycle detection logic in its own class, simplifying the `PackageRestoreDataSource` class.
At some point a bunch of code was moved from the VS layer into the host-agnostic layer. However the namespaces were not updated, and the unit tests were not moved. This commit finalizes that move and makes everything consistent. All these types are internal, so there are no outside dependencies for which moving these types between namespaces would be an issue.
melytc
approved these changes
May 30, 2023
MiYanni
approved these changes
May 30, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9050
In #8239 we added a feature that aimed to detect NuGet package restore loops, and to stop them after a certain number of iterations to prevent endless resource usage.
It turns out that feature never worked due to using a
byte[]as a key in a dictionary.This PR:
byte[]hashing issue by wrapping thebyte[]with a newHashtype that addsEqualsandGetHashCode, makes the type immutable and provides a little more type safety.PackageRestoreDataSourceclass somewhat.Before

After

Microsoft Reviewers: Open in CodeFlow