diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index bb2c835b39..8bbda9904b 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -1280,12 +1280,12 @@ func (d *Downloader) fetchReceipts(from uint64, beaconMode bool) error { // queue until the stream ends or a failure occurs. func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode bool) error { var ( - mode = d.getMode() - gotHeaders = false // Wait for batches of headers to process - secondTimer = time.NewTimer(time.Second) + mode = d.getMode() + gotHeaders = false // Wait for batches of headers to process + timer = time.NewTimer(time.Second) ) - defer secondTimer.Stop() + defer timer.Stop() for { select { @@ -1407,11 +1407,11 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode if mode == FullSync || mode == SnapSync { // If we've reached the allowed number of pending headers, stall a bit for d.queue.PendingBodies() >= maxQueuedHeaders || d.queue.PendingReceipts() >= maxQueuedHeaders { - secondTimer.Reset(time.Second) + timer.Reset(time.Second) select { case <-d.cancelCh: return errCanceled - case <-secondTimer.C: + case <-timer.C: } } // Otherwise insert the headers for content retrieval @@ -1576,11 +1576,11 @@ func (d *Downloader) processSnapSyncContent() error { // Note, there's no issue with memory piling up since after 64 blocks the // pivot will forcefully move so these accumulators will be dropped. var ( - oldPivot *fetchResult // Locked in pivot block, might change eventually - oldTail []*fetchResult // Downloaded content after the pivot - secondTimer = time.NewTimer(time.Second) + oldPivot *fetchResult // Locked in pivot block, might change eventually + oldTail []*fetchResult // Downloaded content after the pivot + timer = time.NewTimer(time.Second) ) - defer secondTimer.Stop() + defer timer.Stop() for { // Wait for the next batch of downloaded data to be available. If we have // not yet reached the pivot point, wait blockingly as there's no need to @@ -1663,7 +1663,7 @@ func (d *Downloader) processSnapSyncContent() error { oldPivot = P } // Wait for completion, occasionally checking for pivot staleness - secondTimer.Reset(time.Second) + timer.Reset(time.Second) select { case <-sync.done: if sync.err != nil { @@ -1674,7 +1674,7 @@ func (d *Downloader) processSnapSyncContent() error { } oldPivot = nil - case <-secondTimer.C: + case <-timer.C: oldTail = afterP continue } diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go index 10cfd12d71..8fd027616a 100644 --- a/p2p/simulations/adapters/exec.go +++ b/p2p/simulations/adapters/exec.go @@ -303,7 +303,6 @@ func (n *ExecNode) Stop() error { go func() { waitErr <- n.Cmd.Wait() }() - timer := time.NewTimer(5 * time.Second) defer timer.Stop() diff --git a/p2p/simulations/mocker.go b/p2p/simulations/mocker.go index 1388ef503f..3e6998e94f 100644 --- a/p2p/simulations/mocker.go +++ b/p2p/simulations/mocker.go @@ -65,10 +65,13 @@ func startStop(net *Network, quit chan struct{}, nodeCount int) { if err != nil { panic("Could not startup node network for mocker") } - tick := time.NewTicker(10 * time.Second) - defer tick.Stop() - timer := time.NewTimer(3 * time.Second) + var ( + tick = time.NewTicker(10 * time.Second) + timer = time.NewTimer(3 * time.Second) + ) + + defer tick.Stop() defer timer.Stop() for { diff --git a/p2p/simulations/network.go b/p2p/simulations/network.go index 9c6230d832..95d7eda08a 100644 --- a/p2p/simulations/network.go +++ b/p2p/simulations/network.go @@ -1028,14 +1028,14 @@ func (net *Network) Load(snap *Snapshot) error { } } - snapshotLoadTimeoutTimer := time.NewTimer(snapshotLoadTimeout) - defer snapshotLoadTimeoutTimer.Stop() + timeout := time.NewTimer(snapshotLoadTimeout) + defer timeout.Stop() select { // Wait until all connections from the snapshot are established. case <-allConnected: // Make sure that we do not wait forever. - case <-snapshotLoadTimeoutTimer.C: + case <-timeout.C: return errors.New("snapshot connections not established") } return nil