Skip to content

Commit bc0666f

Browse files
holimankaralabe
authored andcommitted
eth/downloader: fix #15858 by checking if downloader dropPeer function is set (#15992)
1 parent 0662384 commit bc0666f

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

‎eth/downloader/downloader.go‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,13 @@ func (d *Downloader) Synchronise(id string, head common.Hash, td *big.Int, mode
324324
errEmptyHeaderSet, errPeersUnavailable, errTooOld,
325325
errInvalidAncestor, errInvalidChain:
326326
log.Warn("Synchronisation failed, dropping peer", "peer", id, "err", err)
327-
d.dropPeer(id)
328-
327+
if d.dropPeer == nil {
328+
// The dropPeer method is nil when `--copydb` is used for a local copy.
329+
// Timeouts can occur if e.g. compaction hits at the wrong time, and can be ignored
330+
log.Warn("Downloader wants to drop peer, but peerdrop-function is not set", "peer", id)
331+
} else {
332+
d.dropPeer(id)
333+
}
329334
default:
330335
log.Warn("Synchronisation failed, retrying", "err", err)
331336
}
@@ -853,6 +858,12 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64) error {
853858
getHeaders(from)
854859

855860
case <-timeout.C:
861+
if d.dropPeer == nil {
862+
// The dropPeer method is nil when `--copydb` is used for a local copy.
863+
// Timeouts can occur if e.g. compaction hits at the wrong time, and can be ignored
864+
p.log.Warn("Downloader wants to drop peer, but peerdrop-function is not set", "peer", p.id)
865+
break
866+
}
856867
// Header retrieval timed out, consider the peer bad and drop
857868
p.log.Debug("Header request timed out", "elapsed", ttl)
858869
headerTimeoutMeter.Mark(1)
@@ -1071,7 +1082,13 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
10711082
setIdle(peer, 0)
10721083
} else {
10731084
peer.log.Debug("Stalling delivery, dropping", "type", kind)
1074-
d.dropPeer(pid)
1085+
if d.dropPeer == nil {
1086+
// The dropPeer method is nil when `--copydb` is used for a local copy.
1087+
// Timeouts can occur if e.g. compaction hits at the wrong time, and can be ignored
1088+
peer.log.Warn("Downloader wants to drop peer, but peerdrop-function is not set", "peer", pid)
1089+
} else {
1090+
d.dropPeer(pid)
1091+
}
10751092
}
10761093
}
10771094
}

0 commit comments

Comments
 (0)