Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/backend/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ func pushIfNotExist(ctx context.Context, pb *internalpb.ProgressBar, prompt stri
if err != nil {
return err
}
// The ReadCloser returned by PullBlob was previously never closed on
// either path, leaking the underlying file descriptor (or HTTP body)
// for every blob we pushed. Close on the distribution implementation
// returns an error (#50), which is why we still wrap the reader with
// io.NopCloser below, but we DO need to close `content` ourselves.
// See #491.
defer content.Close()
Comment on lines +179 to +185
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The added comment is quite verbose and contains historical context that is better suited for a commit message. Additionally, it partially duplicates the explanation for the io.NopCloser workaround located just below. Consolidating this into a concise note about resource management would improve readability.

Suggested change
// The ReadCloser returned by PullBlob was previously never closed on
// either path, leaking the underlying file descriptor (or HTTP body)
// for every blob we pushed. Close on the distribution implementation
// returns an error (#50), which is why we still wrap the reader with
// io.NopCloser below, but we DO need to close `content` ourselves.
// See #491.
defer content.Close()
// Ensure the blob content is closed to avoid leaking resources (#491).
// We use defer here and io.NopCloser below to work around the distribution
// library's Close() implementation which returns a known error (#50).
defer content.Close()


reader := pb.Add(prompt, desc.Digest.String(), desc.Size, content)
// resolve issue: https://github.com/modelpack/modctl/issues/50
Expand Down
Loading