Skip to content

Commit d6c0c5c

Browse files
committed
fix(backend): close the ReadCloser returned by PullBlob in push
pushIfNotExist pulled each blob's content from the source storage and then handed it to Blobs().Push wrapped in io.NopCloser. The NopCloser is there on purpose (Close on the distribution reader returns an error, see #50), but it also means the original ReadCloser from PullBlob was never closed on any path, leaking a file descriptor or HTTP body per blob. Add a `defer content.Close()` immediately after the nil-error check so the original reader is released on both success and error paths. The existing NopCloser wrapper still prevents Push from calling Close itself, so the workaround for #50 is preserved. Fixes #491 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com> Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
1 parent 73e3a9c commit d6c0c5c

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

pkg/backend/push.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ func pushIfNotExist(ctx context.Context, pb *internalpb.ProgressBar, prompt stri
186186
if err != nil {
187187
return err
188188
}
189+
// The ReadCloser returned by PullBlob was previously never closed on
190+
// either path, leaking the underlying file descriptor (or HTTP body)
191+
// for every blob we pushed. Close on the distribution implementation
192+
// returns an error (#50), which is why we still wrap the reader with
193+
// io.NopCloser below, but we DO need to close `content` ourselves.
194+
// See #491.
195+
defer content.Close()
189196

190197
reader := pb.Add(prompt, desc.Digest.String(), desc.Size, tracker.WrapReader(content))
191198
// resolve issue: https://github.com/modelpack/modctl/issues/50

0 commit comments

Comments
 (0)