@ -1276,7 +1276,10 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode
var (
mode = d . getMode ( )
gotHeaders = false // Wait for batches of headers to process
timer = time . NewTimer ( time . Second )
)
defer timer . Stop ( )
for {
select {
case <- d . cancelCh :
@ -1397,10 +1400,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 {
timer . Reset ( time . Second )
select {
case <- d . cancelCh :
return errCanceled
case <- time . After ( time . Second ) :
case <- timer . C :
}
}
// Otherwise insert the headers for content retrieval
@ -1567,7 +1571,10 @@ func (d *Downloader) processSnapSyncContent() error {
var (
oldPivot * fetchResult // Locked in pivot block, might change eventually
oldTail [ ] * fetchResult // Downloaded content after the pivot
timer = time . NewTimer ( time . Second )
)
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
@ -1650,6 +1657,7 @@ func (d *Downloader) processSnapSyncContent() error {
oldPivot = P
}
// Wait for completion, occasionally checking for pivot staleness
timer . Reset ( time . Second )
select {
case <- sync . done :
if sync . err != nil {
@ -1660,7 +1668,7 @@ func (d *Downloader) processSnapSyncContent() error {
}
oldPivot = nil
case <- time . After ( time . Second ) :
case <- timer . C :
oldTail = afterP
continue
}