-
Notifications
You must be signed in to change notification settings - Fork 3
Fix fd leaks in getContents error paths #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,7 @@ func getContents(c *Caching, reqChunks []uint32, from uint32) (io.ReadCloser, in | |
| if err := checkChunkSize(c, f, idx); err == nil { | ||
| return f, 1, nil | ||
| } | ||
| _ = f.Close() | ||
| } | ||
|
|
||
| // find all hit block. | ||
|
|
@@ -192,6 +193,7 @@ func getContents(c *Caching, reqChunks []uint32, from uint32) (io.ReadCloser, in | |
| chunkFile, _ := getSliceChunkFile(c, availableChunks[index]) | ||
| if chunkFile != nil { | ||
| if err := checkChunkSize(c, chunkFile, idx); err != nil { | ||
| _ = chunkFile.Close() | ||
| _ = c.bucket.Discard(context.Background(), c.id) | ||
| return nil, 0, err | ||
| } | ||
|
Comment on lines
195
to
199
|
||
|
|
@@ -202,6 +204,7 @@ func getContents(c *Caching, reqChunks []uint32, from uint32) (io.ReadCloser, in | |
| // Request is automatically cloned by getUpstreamReader | ||
| reader, err := c.getUpstreamReader(fromByte, toByte, true) | ||
| if err != nil { | ||
| _ = chunkFile.Close() | ||
| return nil, 0, err | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error return from
getSliceChunkFileis ignored here (chunkFile, _ := ...).getSliceChunkFilecan return non-NotExist errors (including EMFILE viaisTooManyFiles), and ignoring it will silently fall back to an upstream fill instead of failing fast. Handle and return the error (similar to the earlierf, err1 := ...branch).