Repository navigation
Stream archives when listing and reading browsed files - #408
Open
abhinavgautam01 wants to merge 1 commit into
Open
abhinavgautam01 wants to merge 1 commit into
abhinavgautam01 wants to merge 1 commit into
Conversation
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.
Closes #386
Problem
Browsing a cached artifact buffered the whole archive in
openArchive. The TAR readers also kept every expanded file body in memory. For non-npm packages the archive was parsed twice: once to detect a common root directory, then again with that prefix stripped. So listing one directory or viewing one small file could allocate memory for the entire expanded archive.Changes
Streaming reader (
internal/server/browse_archive.go)Directory listings and file reads now use
archives.OpenStream:package/prefix stripping and needs a single pass.The listing logic mirrors
archives.Reader.ListDircombined with the prefix wrapper, so paths, synthesized directory entries, ordering and duplicate handling all stay the same.Limits
The existing 512 MB input-size cap stays. These limits are now explicit:
They match what the buffered reader enforced implicitly, so no archive that browsed before is rejected now. A limit failure returns
500witharchive exceeds browse limitsand is logged at warn level. Other archive errors still returnfailed to open archive.Unchanged
Content-Typesniffing,Content-Security-Policy,X-Content-Type-OptionsandContent-Dispositionheaders.404.openArchive, becausediff.Compareneeds a random-accessarchives.Reader.Results
Fixture: a gzip tarball with 1,025 entries and 32 MiB expanded (92 KB compressed).
From
BenchmarkBrowseLargeArchive(B/opandns/op).Tests
New tests in
internal/server/browse_archive_test.goall go through the public browse endpoints:"",/,src,src/,/src, nested, missing, file path).404for missing files and that the first of two duplicate entries wins.gofmt,go vet,golangci-lint(v2.13.1),go test -race ./...and Swagger regeneration all pass locally.Notes
klauspost/compressa direct dependency ingo.mod. ZIP covers the same buffered path.