Skip to content

Commit

Permalink
core/rawdb: wait for background freezing to exit when closing freezer (
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman authored May 17, 2021
1 parent 67e7f61 commit bb9f9cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions core/rawdb/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bb9f9cc

Please sign in to comment.