Skip to content

Commit

Permalink
eth/downloader : avoid timer leak (#96)
Browse files Browse the repository at this point in the history
eth/downloader : avoid timer leak (#90)

Co-authored-by: Ryan He <163962984+ryanmorphl2@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and ryanmorphl2 authored Jun 12, 2024
1 parent 8fba72b commit 2ef66c2
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,11 +995,17 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, head uint64) e

// Start pulling the header chain skeleton until all is done
var (
skeleton = true // Skeleton assembly phase or finishing up
pivoting = false // Whether the next request is pivot verification
ancestor = from
mode = d.getMode()
skeleton = true // Skeleton assembly phase or finishing up
pivoting = false // Whether the next request is pivot verification
ancestor = from
mode = d.getMode()
headerCheckTimer = time.NewTimer(fsHeaderContCheck)
headerDelayedTimer = time.NewTimer(fsHeaderContCheck)
)

defer headerCheckTimer.Stop()
defer headerDelayedTimer.Stop()

for {
// Pull the next batch of headers, it either:
// - Pivot check to see if the chain moved too far
Expand Down Expand Up @@ -1104,8 +1110,9 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, head uint64) e
// Don't abort header fetches while the pivot is downloading
if atomic.LoadInt32(&d.committed) == 0 && pivot <= from {
p.log.Debug("No headers, waiting for pivot commit")
headerCheckTimer.Reset(fsHeaderContCheck)
select {
case <-time.After(fsHeaderContCheck):
case <-headerCheckTimer.C:
continue
case <-d.cancelCh:
return errCanceled
Expand Down Expand Up @@ -1175,8 +1182,9 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, head uint64) e
// skeleton filling
if len(headers) == 0 && !progressed {
p.log.Trace("All headers delayed, waiting")
headerDelayedTimer.Reset(fsHeaderContCheck)
select {
case <-time.After(fsHeaderContCheck):
case <-headerDelayedTimer.C:
continue
case <-d.cancelCh:
return errCanceled
Expand Down

0 comments on commit 2ef66c2

Please sign in to comment.