core/state, eth, trie: stabilize memory use, fix memory leak
This commit is contained in:
@ -1611,7 +1611,13 @@ func (d *Downloader) processFastSyncContent(latest *types.Header) error {
|
||||
// Start syncing state of the reported head block. This should get us most of
|
||||
// the state of the pivot block.
|
||||
sync := d.syncState(latest.Root)
|
||||
defer sync.Cancel()
|
||||
defer func() {
|
||||
// The `sync` object is replaced every time the pivot moves. We need to
|
||||
// defer close the very last active one, hence the lazy evaluation vs.
|
||||
// calling defer sync.Cancel() !!!
|
||||
sync.Cancel()
|
||||
}()
|
||||
|
||||
closeOnErr := func(s *stateSync) {
|
||||
if err := s.Wait(); err != nil && err != errCancelStateFetch && err != errCanceled {
|
||||
d.queue.Close() // wake up Results
|
||||
@ -1674,9 +1680,8 @@ func (d *Downloader) processFastSyncContent(latest *types.Header) error {
|
||||
// If new pivot block found, cancel old state retrieval and restart
|
||||
if oldPivot != P {
|
||||
sync.Cancel()
|
||||
|
||||
sync = d.syncState(P.Header.Root)
|
||||
defer sync.Cancel()
|
||||
|
||||
go closeOnErr(sync)
|
||||
oldPivot = P
|
||||
}
|
||||
|
Reference in New Issue
Block a user