diff --git a/core/rawdb/eradb/eradb.go b/core/rawdb/eradb/eradb.go index ae19016cc6..6236640842 100644 --- a/core/rawdb/eradb/eradb.go +++ b/core/rawdb/eradb/eradb.go @@ -55,8 +55,6 @@ func New(datadir string) (*EraDatabase, error) { return nil, err } db := &EraDatabase{datadir: datadir, cache: lru.NewCache[uint64, *era.Era](openFileLimit)} - // Take care to close era1 files when they are evicted or replaced - // in the cache to avoid leaking file descriptors. closeEra := func(epoch uint64, e *era.Era) { if e == nil { log.Warn("Era1 cache contained nil value", "epoch", epoch) @@ -67,7 +65,10 @@ func New(datadir string) (*EraDatabase, error) { } } + // Take care to close era1 files when they are evicted from cache. db.cache.OnEvicted(closeEra) + // Concurrently calling GetRaw* methods can cause the same era1 file to be + // opened multiple times. db.cache.OnReplaced(closeEra) log.Info("Opened erastore", "datadir", datadir) return db, nil