Fix file handlers not being closed after calls to ImageStore.GetBlob

This is to fixes hitting the FD limit when reading blobs from the disk in the graphql API

Signed-off-by: Andrei Aaron <andaaron@cisco.com>
This commit is contained in:
Andrei Aaron
2022-08-19 10:38:59 +00:00
committed by Ramkumar Chinchani
parent 74630ed3a0
commit bd9ad998cd
10 changed files with 83 additions and 54 deletions
+1
View File
@@ -655,6 +655,7 @@ func (rh *RouteHandler) GetBlob(response http.ResponseWriter, request *http.Requ
return
}
defer repo.Close()
response.Header().Set("Content-Length", fmt.Sprintf("%d", blen))
response.Header().Set(constants.DistContentDigestKey, digest)
+4 -4
View File
@@ -405,8 +405,8 @@ func TestRoutes(t *testing.T) {
"digest": "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621",
},
&mocks.MockedImageStore{
GetBlobFn: func(repo, digest, mediaType string) (io.Reader, int64, error) {
return bytes.NewBuffer([]byte("")), 0, zerr.ErrRepoNotFound
GetBlobFn: func(repo, digest, mediaType string) (io.ReadCloser, int64, error) {
return io.NopCloser(bytes.NewBuffer([]byte(""))), 0, zerr.ErrRepoNotFound
},
})
So(statusCode, ShouldEqual, http.StatusNotFound)
@@ -418,8 +418,8 @@ func TestRoutes(t *testing.T) {
"digest": "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621",
},
&mocks.MockedImageStore{
GetBlobFn: func(repo, digest, mediaType string) (io.Reader, int64, error) {
return bytes.NewBuffer([]byte("")), 0, zerr.ErrBadBlobDigest
GetBlobFn: func(repo, digest, mediaType string) (io.ReadCloser, int64, error) {
return io.NopCloser(bytes.NewBuffer([]byte(""))), 0, zerr.ErrBadBlobDigest
},
})
So(statusCode, ShouldEqual, http.StatusBadRequest)