stop and close iterator

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2025-08-06 15:04:18 +08:00 committed by Gary Rong
parent cd6b23b3a2
commit b34e366bb4

View file

@ -61,7 +61,7 @@ type stateSizeGenerator struct {
// Generator state // Generator state
running bool running bool
abort chan chan struct{} abort chan struct{}
done chan struct{} done chan struct{}
// Metrics state // Metrics state
@ -74,7 +74,7 @@ func newStateSizeGenerator(db ethdb.KeyValueStore, sdb Database, root common.Has
return &stateSizeGenerator{ return &stateSizeGenerator{
db: db, db: db,
sdb: sdb, sdb: sdb,
abort: make(chan chan struct{}), abort: make(chan struct{}),
done: make(chan struct{}), done: make(chan struct{}),
metrics: &StateSizeMetrics{Root: root}, metrics: &StateSizeMetrics{Root: root},
} }
@ -95,9 +95,7 @@ func (g *stateSizeGenerator) stop() {
if !g.running { if !g.running {
return return
} }
ch := make(chan struct{}) close(g.abort)
g.abort <- ch
<-ch
g.running = false g.running = false
} }
@ -156,10 +154,9 @@ func (g *stateSizeGenerator) initializeMetrics() {
count++ count++
bytes += uint64(len(iter.Key()) + len(iter.Value())) bytes += uint64(len(iter.Key()) + len(iter.Value()))
// Check for abort
select { select {
case abort := <-g.abort: case <-g.abort:
close(abort) return
default: default:
} }
} }