fix: client panic (#719)

* fix: client panic

Signed-off-by: Jim Ma <majinjing3@gmail.com>

* chore: update ginkgo version

Signed-off-by: Jim Ma <majinjing3@gmail.com>

* chore: avoid send failed piece hang

Signed-off-by: Jim Ma <majinjing3@gmail.com>
This commit is contained in:
Jim Ma 2021-10-13 11:36:13 +08:00 committed by Gaius
parent 03b0949ee8
commit 77bb686cbe
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
5 changed files with 22 additions and 8 deletions

View File

@ -369,7 +369,6 @@ func (pt *peerTask) pullSinglePiece(cleanUnfinishedFunc func()) {
func (pt *peerTask) pullPiecesFromPeers(cleanUnfinishedFunc func()) { func (pt *peerTask) pullPiecesFromPeers(cleanUnfinishedFunc func()) {
defer func() { defer func() {
close(pt.failedPieceCh)
cleanUnfinishedFunc() cleanUnfinishedFunc()
}() }()
@ -605,10 +604,10 @@ func (pt *peerTask) waitFailedPiece() (int32, bool) {
// use no default branch select to wait failed piece or exit // use no default branch select to wait failed piece or exit
select { select {
case <-pt.done: case <-pt.done:
pt.Infof("peer task done, stop wait failed piece") pt.Infof("peer task done, stop to wait failed piece")
return -1, false return -1, false
case <-pt.ctx.Done(): case <-pt.ctx.Done():
pt.Debugf("context done due to %s, stop wait failed piece", pt.ctx.Err()) pt.Debugf("context done due to %s, stop to wait failed piece", pt.ctx.Err())
return -1, false return -1, false
case failed := <-pt.failedPieceCh: case failed := <-pt.failedPieceCh:
pt.Warnf("download piece/%d failed, retry", failed) pt.Warnf("download piece/%d failed, retry", failed)

View File

@ -238,8 +238,15 @@ func (pt *filePeerTask) ReportPieceResult(result *pieceTaskResult) error {
if !result.pieceResult.Success { if !result.pieceResult.Success {
result.pieceResult.FinishedCount = pt.readyPieces.Settled() result.pieceResult.FinishedCount = pt.readyPieces.Settled()
_ = pt.peerPacketStream.Send(result.pieceResult) _ = pt.peerPacketStream.Send(result.pieceResult)
pt.failedPieceCh <- result.pieceResult.PieceInfo.PieceNum select {
pt.Errorf("%d download failed, retry later", result.piece.PieceNum) case <-pt.done:
pt.Infof("peer task done, stop to send failed piece")
case <-pt.ctx.Done():
pt.Debugf("context done due to %s, stop to send failed piece", pt.ctx.Err())
case pt.failedPieceCh <- result.pieceResult.PieceInfo.PieceNum:
pt.Warnf("%d download failed, retry later", result.piece.PieceNum)
}
return nil return nil
} }

View File

@ -194,7 +194,14 @@ func (s *streamPeerTask) ReportPieceResult(result *pieceTaskResult) error {
// retry failed piece // retry failed piece
if !result.pieceResult.Success { if !result.pieceResult.Success {
_ = s.peerPacketStream.Send(result.pieceResult) _ = s.peerPacketStream.Send(result.pieceResult)
s.failedPieceCh <- result.pieceResult.PieceInfo.PieceNum select {
case <-s.done:
s.Infof("peer task done, stop to send failed piece")
case <-s.ctx.Done():
s.Debugf("context done due to %s, stop to send failed piece", s.ctx.Err())
case s.failedPieceCh <- result.pieceResult.PieceInfo.PieceNum:
s.Warnf("%d download failed, retry later", result.piece.PieceNum)
}
return nil return nil
} }

2
go.mod
View File

@ -45,7 +45,7 @@ require (
github.com/mitchellh/mapstructure v1.4.1 github.com/mitchellh/mapstructure v1.4.1
github.com/montanaflynn/stats v0.6.6 github.com/montanaflynn/stats v0.6.6
github.com/olekukonko/tablewriter v0.0.5 github.com/olekukonko/tablewriter v0.0.5
github.com/onsi/ginkgo v1.16.4 github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.14.0 github.com/onsi/gomega v1.14.0
github.com/opencontainers/go-digest v1.0.0 github.com/opencontainers/go-digest v1.0.0
github.com/pborman/uuid v1.2.1 github.com/pborman/uuid v1.2.1

3
go.sum
View File

@ -647,8 +647,9 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108
github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg= github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg=
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=