mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-11 17:31:35 +00:00
core/rawdb: fix file descriptor leak in freezer error paths (#34735)
In openFreezerFileForAppend, if Seek fails after the file is successfully opened, the file handle is not closed, leaking a descriptor. Similarly in newTable, if opening the meta file fails, the already-opened index file is not closed. And if newMetadata fails, both the index and meta files are leaked. Under repeated error conditions (e.g., corrupted filesystem), these leaks accumulate and may exhaust the OS file descriptor limit, causing cascading failures.
This commit is contained in:
parent
8c7d61fcfe
commit
5af5510b1e
2 changed files with 5 additions and 0 deletions
|
|
@ -157,6 +157,7 @@ func newTable(path string, name string, readMeter, writeMeter *metrics.Meter, si
|
|||
}
|
||||
meta, err = openFreezerFileForReadOnly(filepath.Join(path, fmt.Sprintf("%s.meta", name)))
|
||||
if err != nil {
|
||||
index.Close()
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
|
|
@ -166,6 +167,7 @@ func newTable(path string, name string, readMeter, writeMeter *metrics.Meter, si
|
|||
}
|
||||
meta, err = openFreezerFileForAppend(filepath.Join(path, fmt.Sprintf("%s.meta", name)))
|
||||
if err != nil {
|
||||
index.Close()
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
@ -173,6 +175,8 @@ func newTable(path string, name string, readMeter, writeMeter *metrics.Meter, si
|
|||
// is detected.
|
||||
metadata, err := newMetadata(meta)
|
||||
if err != nil {
|
||||
meta.Close()
|
||||
index.Close()
|
||||
return nil, err
|
||||
}
|
||||
// Create the table and repair any past inconsistency
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ func openFreezerFileForAppend(filename string) (*os.File, error) {
|
|||
}
|
||||
// Seek to end for append
|
||||
if _, err = file.Seek(0, io.SeekEnd); err != nil {
|
||||
file.Close()
|
||||
return nil, err
|
||||
}
|
||||
return file, nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue