Skip to content

Commit 392219c

Browse files
Copilotsendya
andcommitted
fix: close file descriptors in getContents error paths to prevent fd leaks
Co-authored-by: sendya <5404542+sendya@users.noreply.github.com>
1 parent 016bec8 commit 392219c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

server/middleware/caching/internal.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func getContents(c *Caching, reqChunks []uint32, from uint32) (io.ReadCloser, in
174174
if err := checkChunkSize(c, f, idx); err == nil {
175175
return f, 1, nil
176176
}
177+
_ = f.Close()
177178
}
178179

179180
// find all hit block.
@@ -192,6 +193,7 @@ func getContents(c *Caching, reqChunks []uint32, from uint32) (io.ReadCloser, in
192193
chunkFile, _ := getSliceChunkFile(c, availableChunks[index])
193194
if chunkFile != nil {
194195
if err := checkChunkSize(c, chunkFile, idx); err != nil {
196+
_ = chunkFile.Close()
195197
_ = c.bucket.Discard(context.Background(), c.id)
196198
return nil, 0, err
197199
}
@@ -202,6 +204,7 @@ func getContents(c *Caching, reqChunks []uint32, from uint32) (io.ReadCloser, in
202204
// Request is automatically cloned by getUpstreamReader
203205
reader, err := c.getUpstreamReader(fromByte, toByte, true)
204206
if err != nil {
207+
_ = chunkFile.Close()
205208
return nil, 0, err
206209
}
207210

0 commit comments

Comments
 (0)