Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #742 from wybzju/bugfix
Browse files Browse the repository at this point in the history
bugfix: the dfget will wait forever when the final piece failed
  • Loading branch information
starnop authored Aug 15, 2019
2 parents 4439903 + a0331aa commit fb377a9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dfget/core/downloader/p2p_downloader/p2p_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ func (p2p *P2PDownloader) Run() error {
} else if code == constants.CodePeerFinish {
p2p.finishTask(response, clientWriter)
return nil
} else if code == constants.CodePeerWait {
continue
}

logrus.Warnf("request piece result:%v", response)
Expand Down Expand Up @@ -236,6 +238,9 @@ func (p2p *P2PDownloader) pullPieceTask(item *Piece) (
if res.Code != constants.CodePeerWait {
break
}
if p2p.queue.Len() > 0 {
break
}
sleepTime := time.Duration(rand.Intn(1400)+600) * time.Millisecond
logrus.Infof("pull piece task(%+v) result:%s and sleep %.3fs", item, res, sleepTime.Seconds())
time.Sleep(sleepTime)
Expand All @@ -245,7 +250,8 @@ func (p2p *P2PDownloader) pullPieceTask(item *Piece) (
if res != nil && !(res.Code != constants.CodePeerContinue &&
res.Code != constants.CodePeerFinish &&
res.Code != constants.CodePeerLimited &&
res.Code != constants.Success) {
res.Code != constants.Success &&
res.Code != constants.CodePeerWait) {
return res, err
}

Expand Down

0 comments on commit fb377a9

Please sign in to comment.