mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
fix(promql/query_logger): close file in error handling (#13948)
Signed-off-by: guoguangwu <guoguangwug@gmail.com>
This commit is contained in:
parent
34ee8c6078
commit
9fda9443d4
|
@ -96,12 +96,14 @@ func getMMapedFile(filename string, filesize int, logger log.Logger) ([]byte, io
|
|||
|
||||
err = file.Truncate(int64(filesize))
|
||||
if err != nil {
|
||||
file.Close()
|
||||
level.Error(logger).Log("msg", "Error setting filesize.", "filesize", filesize, "err", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
fileAsBytes, err := mmap.Map(file, mmap.RDWR, 0)
|
||||
if err != nil {
|
||||
file.Close()
|
||||
level.Error(logger).Log("msg", "Failed to mmap", "file", filename, "Attempted size", filesize, "err", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
|
@ -110,10 +110,7 @@ func TestMMapFile(t *testing.T) {
|
|||
filename := file.Name()
|
||||
defer os.Remove(filename)
|
||||
|
||||
fileAsBytes, closer, err := getMMapedFile(filename, 2, nil)
|
||||
if err != nil {
|
||||
t.Cleanup(func() { closer.Close() })
|
||||
}
|
||||
fileAsBytes, _, err := getMMapedFile(filename, 2, nil)
|
||||
|
||||
require.NoError(t, err)
|
||||
copy(fileAsBytes, "ab")
|
||||
|
|
Loading…
Reference in a new issue