Skip to content

Commit c40cba5

Browse files
authored
chore: release failed running piece (#3214)
Signed-off-by: Jim Ma <[email protected]>
1 parent 328b432 commit c40cba5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

client/daemon/peer/peertask_conductor.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,11 +1086,16 @@ func (pt *peerTaskConductor) downloadPiece(workerID int32, request *DownloadPiec
10861086
pt.runningPieces.Set(request.piece.PieceNum)
10871087
pt.runningPiecesLock.Unlock()
10881088

1089-
defer func() {
1090-
pt.runningPiecesLock.Lock()
1091-
pt.runningPieces.Clean(request.piece.PieceNum)
1092-
pt.runningPiecesLock.Unlock()
1093-
}()
1089+
var cleanRunningPieceDone bool
1090+
cleanRunningPiece := func() {
1091+
if cleanRunningPieceDone {
1092+
cleanRunningPieceDone = true
1093+
pt.runningPiecesLock.Lock()
1094+
pt.runningPieces.Clean(request.piece.PieceNum)
1095+
pt.runningPiecesLock.Unlock()
1096+
}
1097+
}
1098+
defer cleanRunningPiece()
10941099

10951100
ctx, span := tracer.Start(pt.pieceDownloadCtx, fmt.Sprintf(config.SpanDownloadPiece, request.piece.PieceNum))
10961101
span.SetAttributes(config.AttributePiece.Int(int(request.piece.PieceNum)))
@@ -1117,6 +1122,9 @@ func (pt *peerTaskConductor) downloadPiece(workerID int32, request *DownloadPiec
11171122
pt.Infof("switch to back source, skip send failed piece")
11181123
return result
11191124
}
1125+
1126+
// clean running piece first
1127+
cleanRunningPiece()
11201128
attempt, success := pt.pieceTaskSyncManager.acquire(
11211129
&commonv1.PieceTaskRequest{
11221130
Limit: 1,

0 commit comments

Comments
 (0)