Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
bugfix: the dfget will wait forever when the final piece failed
Browse files Browse the repository at this point in the history
Signed-off-by: wybzju <[email protected]>
  • Loading branch information
wybzju committed Jul 31, 2019
1 parent c86ccf5 commit a0331aa
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 @@ -178,6 +178,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 @@ -233,6 +235,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 @@ -242,7 +247,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 a0331aa

Please sign in to comment.