Skip to content

Commit 4c54dcc

Browse files
fix(redundancy): prevent goroutine leak in runStrategy
1 parent e441d61 commit 4c54dcc

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

pkg/file/redundancy/getter/getter.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,25 @@ func (g *decoder) runStrategy(s Strategy) error {
252252
}(i)
253253
}
254254

255+
var result error
256+
readCount := 0
255257
for range c {
256-
if g.fetchedCnt.Load() >= int32(g.shardCnt) {
257-
return nil
258+
readCount++
259+
// check for success
260+
if result == nil && g.fetchedCnt.Load() >= int32(g.shardCnt) {
261+
result = nil
262+
}
263+
// check for failure
264+
if result == nil && g.failedCnt.Load() > int32(allowedErrs) {
265+
result = errStrategyFailed
258266
}
259-
if g.failedCnt.Load() > int32(allowedErrs) {
260-
return errStrategyFailed
267+
// continue reading to ensure all goroutines complete
268+
if readCount >= len(m) {
269+
break
261270
}
262271
}
263272

264-
return nil
273+
return result
265274
}
266275

267276
// recover wraps the stages of data shard recovery:

0 commit comments

Comments
 (0)