From 12558635baf1afc19937a9a36ba80255b4a03027 Mon Sep 17 00:00:00 2001 From: ray Date: Thu, 16 Apr 2026 14:19:40 +0800 Subject: [PATCH] core/rawdb: fix file descriptor leak in freezer error paths 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. --- core/rawdb/freezer_table.go | 4 ++++ core/rawdb/freezer_utils.go | 1 + 2 files changed, 5 insertions(+) diff --git a/core/rawdb/freezer_table.go b/core/rawdb/freezer_table.go index 280f6e1aaa..c770e89989 100644 --- a/core/rawdb/freezer_table.go +++ b/core/rawdb/freezer_table.go @@ -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 diff --git a/core/rawdb/freezer_utils.go b/core/rawdb/freezer_utils.go index 7f1a978b63..68e77d8a06 100644 --- a/core/rawdb/freezer_utils.go +++ b/core/rawdb/freezer_utils.go @@ -129,6 +129,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