core/rawdb: capture open file error and fix resource leak (#33147)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

This commit is contained in:
Lucia 2025-11-11 21:01:37 +13:00 committed by GitHub
parent 5f4cc3f57d
commit 7368b34a4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 5 deletions

View file

@ -303,6 +303,7 @@ func (db *Store) openEraFile(epoch uint64) (*era.Era, error) {
}
// Sanity-check start block.
if e.Start()%uint64(era.MaxEra1Size) != 0 {
e.Close()
return nil, fmt.Errorf("pre-merge era1 file has invalid boundary. %d %% %d != 0", e.Start(), era.MaxEra1Size)
}
log.Debug("Opened era1 file", "epoch", epoch)

View file

@ -51,12 +51,18 @@ func newFreezerBatch(f *Freezer) *freezerBatch {
// Append adds an RLP-encoded item of the given kind.
func (batch *freezerBatch) Append(kind string, num uint64, item interface{}) error {
return batch.tables[kind].Append(num, item)
if table := batch.tables[kind]; table != nil {
return table.Append(num, item)
}
return errUnknownTable
}
// AppendRaw adds an item of the given kind.
func (batch *freezerBatch) AppendRaw(kind string, num uint64, item []byte) error {
return batch.tables[kind].AppendRaw(num, item)
if table := batch.tables[kind]; table != nil {
return table.AppendRaw(num, item)
}
return errUnknownTable
}
// reset initializes the batch.

View file

@ -1196,8 +1196,7 @@ func (t *freezerTable) sizeNolock() (uint64, error) {
}
// advanceHead should be called when the current head file would outgrow the file limits,
// and a new file must be opened. The caller of this method must hold the write-lock
// before calling this method.
// and a new file must be opened. This method acquires the write-lock internally.
func (t *freezerTable) advanceHead() error {
t.lock.Lock()
defer t.lock.Unlock()
@ -1218,7 +1217,9 @@ func (t *freezerTable) advanceHead() error {
return err
}
t.releaseFile(t.headId)
t.openFile(t.headId, openFreezerFileForReadOnly)
if _, err := t.openFile(t.headId, openFreezerFileForReadOnly); err != nil {
return err
}
// Swap out the current head.
t.head = newHead