Skip to content

Commit

Permalink
fix panic
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Mar 4, 2019
1 parent 9f90cf0 commit 3c7d069
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions torrent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,20 @@ func (t *torrent) run() {
t.downloadSpeed.Tick()
t.uploadSpeed.Tick()
case pe := <-t.peerSnubbedC:
// Mark slow peer as snubbed and don't select that peer in piece picker
pe.Snubbed = true
// Mark slow peer as snubbed to skip that peer in piece picker
if pd, ok := t.pieceDownloaders[pe]; ok {
if _, ok := t.pieceDownloadersChoked[pe]; ok {
panic("piece download is choked")
// Snub timer is already stopped on choke message but may fire anyway.
if pe.PeerChoking {
break
}
pe.Snubbed = true
t.pieceDownloadersSnubbed[pe] = pd
if t.piecePicker != nil {
t.piecePicker.HandleSnubbed(pe, pd.Piece.Index)
}
t.startPieceDownloaders()
} else if id, ok := t.infoDownloaders[pe]; ok {
pe.Snubbed = true
t.infoDownloadersSnubbed[pe] = id
t.startInfoDownloaders()
}
Expand Down

0 comments on commit 3c7d069

Please sign in to comment.