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

always directly download nupkg and cache the tfms #9230

Merged
merged 2 commits into from Mar 7, 2024

Conversation

brettfo
Copy link
Collaborator

@brettfo brettfo commented Mar 6, 2024

Internal logs were showing Zip::Error when trying to unpack the .nupkg inside compatibility_checker.rb. The .nupkg contents were being cached, but when those contents are passed to Zip::File.open_buffer() the contents were changed which meant that subsequent attempts to open the zip stream might fail because it suddenly wasn't a valid zip archive. The size increase didn't always result in a failure to open the zip, only sometimes. I wasn't able to find any information about open_buffer() changing the buffer contents/increasing the size.

I was able to manually verify this against a test repo (100% repro before the fix, 0% after), but I couldn't figure out why or when to add a unit test and it didn't seem appropriate to check in a binary zip file to this repo. Instead I don't cache the .nupkg contents and will always fetch a fresh copy, but do cache the TFM results so in practice this should be the same behavior as before.

Since this behavior came out of another bug modifying how we download .nupkg contents (see #9204), I decided it would be beneficial to explicitly state what's going on in the downloader with a comment and a direct call to the Excon download API. This way if the behavior of the previous method ever changes, this functionality won't be broken.

@brettfo brettfo requested a review from a team as a code owner March 6, 2024 20:43
@github-actions github-actions bot added the L: dotnet:nuget NuGet packages via nuget or dotnet label Mar 6, 2024
@@ -66,23 +66,31 @@ def project_tfms
end

def fetch_package_tfms(dependency_version)
nupkg_buffer = NupkgFetcher.fetch_nupkg_buffer(dependency_urls, dependency.name, dependency_version)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The only change to this function is wrapping the body in begin/end so the result can be cached. No change otherwise.

@@ -111,7 +111,13 @@ def self.fetch_stream(stream_url, auth_header, max_redirects = 5)
current_redirects = 0

loop do
response = fetch_url_with_auth(current_url, auth_header)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fetch_url_with_auth was caching the result, but apparently repeatedly passing the result to Zip::File.open_buffer() will result in a corrupted buffer, so the fix is to always download and to not cache anything.

@abdulapopoola abdulapopoola merged commit 1d431ba into main Mar 7, 2024
86 checks passed
@abdulapopoola abdulapopoola deleted the dev/brettfo/nupkg-zip-handling branch March 7, 2024 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: dotnet:nuget NuGet packages via nuget or dotnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants