mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
eth/downloader : avoid timer leak
This commit is contained in:
parent
2e06fbd409
commit
9a15755f10
1 changed files with 13 additions and 6 deletions
|
|
@ -1015,11 +1015,16 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, head uint64) e
|
||||||
|
|
||||||
// Start pulling the header chain skeleton until all is done
|
// Start pulling the header chain skeleton until all is done
|
||||||
var (
|
var (
|
||||||
skeleton = true // Skeleton assembly phase or finishing up
|
skeleton = true // Skeleton assembly phase or finishing up
|
||||||
pivoting = false // Whether the next request is pivot verification
|
pivoting = false // Whether the next request is pivot verification
|
||||||
ancestor = from
|
ancestor = from
|
||||||
mode = d.getMode()
|
mode = d.getMode()
|
||||||
|
headerCheckTimer = time.NewTimer(fsHeaderContCheck)
|
||||||
|
headerDelayedTimer = time.NewTimer(fsHeaderContCheck)
|
||||||
)
|
)
|
||||||
|
defer headerCheckTimer.Stop()
|
||||||
|
defer headerDelayedTimer.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Pull the next batch of headers, it either:
|
// Pull the next batch of headers, it either:
|
||||||
// - Pivot check to see if the chain moved too far
|
// - Pivot check to see if the chain moved too far
|
||||||
|
|
@ -1124,8 +1129,9 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, head uint64) e
|
||||||
// Don't abort header fetches while the pivot is downloading
|
// Don't abort header fetches while the pivot is downloading
|
||||||
if !d.committed.Load() && pivot <= from {
|
if !d.committed.Load() && pivot <= from {
|
||||||
p.log.Debug("No headers, waiting for pivot commit")
|
p.log.Debug("No headers, waiting for pivot commit")
|
||||||
|
headerCheckTimer.Reset(fsHeaderContCheck)
|
||||||
select {
|
select {
|
||||||
case <-time.After(fsHeaderContCheck):
|
case <-headerCheckTimer.C:
|
||||||
continue
|
continue
|
||||||
case <-d.cancelCh:
|
case <-d.cancelCh:
|
||||||
return errCanceled
|
return errCanceled
|
||||||
|
|
@ -1195,8 +1201,9 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, head uint64) e
|
||||||
// skeleton filling
|
// skeleton filling
|
||||||
if len(headers) == 0 && !progressed {
|
if len(headers) == 0 && !progressed {
|
||||||
p.log.Trace("All headers delayed, waiting")
|
p.log.Trace("All headers delayed, waiting")
|
||||||
|
headerDelayedTimer.Reset(fsHeaderContCheck)
|
||||||
select {
|
select {
|
||||||
case <-time.After(fsHeaderContCheck):
|
case <-headerDelayedTimer.C:
|
||||||
continue
|
continue
|
||||||
case <-d.cancelCh:
|
case <-d.cancelCh:
|
||||||
return errCanceled
|
return errCanceled
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue