Unverified Commit bb9f9ccf authored by Martin Holst Swende's avatar Martin Holst Swende Committed by GitHub

core/rawdb: wait for background freezing to exit when closing freezer (#22878)

parent 67e7f61a
......@@ -197,7 +197,11 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezer string, namespace st
}
// Freezer is consistent with the key-value database, permit combining the two
if !frdb.readonly {
go frdb.freeze(db)
frdb.wg.Add(1)
go func() {
frdb.freeze(db)
frdb.wg.Done()
}()
}
return &freezerdb{
KeyValueStore: db,
......
......@@ -84,6 +84,7 @@ type freezer struct {
trigger chan chan struct{} // Manual blocking freeze trigger, test determinism
quit chan struct{}
wg sync.WaitGroup
closeOnce sync.Once
}
......@@ -145,6 +146,8 @@ func (f *freezer) Close() error {
var errs []error
f.closeOnce.Do(func() {
close(f.quit)
// Wait for any background freezing to stop
f.wg.Wait()
for _, table := range f.tables {
if err := table.Close(); err != nil {
errs = append(errs, err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment