eth/downloader: fix #15858 by checking if downloader dropPeer function is set (#15992)

pull/16020/head
Martin Holst Swende 7 years ago committed by Péter Szilágyi
parent 0662384d29
commit bc0666fb27
  1. 19
      eth/downloader/downloader.go

@ -324,8 +324,13 @@ func (d *Downloader) Synchronise(id string, head common.Hash, td *big.Int, mode
errEmptyHeaderSet, errPeersUnavailable, errTooOld, errEmptyHeaderSet, errPeersUnavailable, errTooOld,
errInvalidAncestor, errInvalidChain: errInvalidAncestor, errInvalidChain:
log.Warn("Synchronisation failed, dropping peer", "peer", id, "err", err) log.Warn("Synchronisation failed, dropping peer", "peer", id, "err", err)
if d.dropPeer == nil {
// The dropPeer method is nil when `--copydb` is used for a local copy.
// Timeouts can occur if e.g. compaction hits at the wrong time, and can be ignored
log.Warn("Downloader wants to drop peer, but peerdrop-function is not set", "peer", id)
} else {
d.dropPeer(id) d.dropPeer(id)
}
default: default:
log.Warn("Synchronisation failed, retrying", "err", err) log.Warn("Synchronisation failed, retrying", "err", err)
} }
@ -853,6 +858,12 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64) error {
getHeaders(from) getHeaders(from)
case <-timeout.C: case <-timeout.C:
if d.dropPeer == nil {
// The dropPeer method is nil when `--copydb` is used for a local copy.
// Timeouts can occur if e.g. compaction hits at the wrong time, and can be ignored
p.log.Warn("Downloader wants to drop peer, but peerdrop-function is not set", "peer", p.id)
break
}
// Header retrieval timed out, consider the peer bad and drop // Header retrieval timed out, consider the peer bad and drop
p.log.Debug("Header request timed out", "elapsed", ttl) p.log.Debug("Header request timed out", "elapsed", ttl)
headerTimeoutMeter.Mark(1) headerTimeoutMeter.Mark(1)
@ -1071,10 +1082,16 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
setIdle(peer, 0) setIdle(peer, 0)
} else { } else {
peer.log.Debug("Stalling delivery, dropping", "type", kind) peer.log.Debug("Stalling delivery, dropping", "type", kind)
if d.dropPeer == nil {
// The dropPeer method is nil when `--copydb` is used for a local copy.
// Timeouts can occur if e.g. compaction hits at the wrong time, and can be ignored
peer.log.Warn("Downloader wants to drop peer, but peerdrop-function is not set", "peer", pid)
} else {
d.dropPeer(pid) d.dropPeer(pid)
} }
} }
} }
}
// If there's nothing more to fetch, wait or terminate // If there's nothing more to fetch, wait or terminate
if pending() == 0 { if pending() == 0 {
if !inFlight() && finished { if !inFlight() && finished {

Loading…
Cancel
Save