Skip to content

Commit 23b36e5

Browse files
committed
refactor: releaseWorkerPools()
1 parent e4716bc commit 23b36e5

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

core/state/trie_prefetcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ func newTriePrefetcher(db Database, root common.Hash, namespace string, opts ...
7979
// close iterates over all the subfetchers, aborts any that were left spinning
8080
// and reports the stats to the metrics subsystem.
8181
func (p *triePrefetcher) close() {
82-
p.abortFetchersAndReleaseWorkerPools()
8382
for _, fetcher := range p.fetchers {
8483
fetcher.abort() // safe to do multiple times
8584

@@ -105,6 +104,7 @@ func (p *triePrefetcher) close() {
105104
}
106105
}
107106
}
107+
p.releaseWorkerPools()
108108
// Clear out all fetchers (will crash on a second call, deliberate)
109109
p.fetchers = nil
110110
}

core/state/trie_prefetcher.libevm.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,11 @@ func (c *prefetcherConfig) applyTo(sf *subfetcher) {
7171
}
7272
}
7373

74-
func (p *triePrefetcher) abortFetchersAndReleaseWorkerPools() {
75-
// Calling abort() sequentially may result in later fetchers accepting new
76-
// work in the interim.
77-
var wg sync.WaitGroup
78-
for _, f := range p.fetchers {
79-
wg.Add(1)
80-
go func(f *subfetcher) {
81-
f.abort()
82-
wg.Done()
83-
}(f)
84-
}
85-
86-
// A WorkerPool is allowed to be shared between fetchers so we MUST wait for
87-
// them to finish all tasks otherwise they could call Execute() after
88-
// Done(), which we guarantee in the public API to be impossible.
89-
wg.Wait()
74+
// releaseWorkerPools calls Done() on all [WorkerPool]s. This MUST only be
75+
// called after [subfetcher.abort] returns on ALL fetchers as a pool is allowed
76+
// to be shared between them. This is because we guarantee in the public API
77+
// that no further calls will be made to Execute() after a call to Done().
78+
func (p *triePrefetcher) releaseWorkerPools() {
9079
for _, f := range p.fetchers {
9180
if w := f.pool.workers; w != nil {
9281
w.Done()

0 commit comments

Comments
 (0)