Skip to content

Commit

Permalink
honor canceled context and do not leak on mergeChannels (minio#15034)
Browse files Browse the repository at this point in the history
mergeEntryChannels has the potential to perpetually
wait on the results channel, context might be closed
and we did not honor the caller context canceling.
  • Loading branch information
harshavardhana authored and Anis Elleuch committed Dec 12, 2022
1 parent 6a78a92 commit 2d00f7d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions cmd/metacache-entries.go
Expand Up @@ -686,8 +686,12 @@ func mergeEntryChannels(ctx context.Context, in []chan metaCacheEntry, out chan<
}
}
if best.name > last {
out <- *best
last = best.name
select {
case <-ctxDone:
return ctx.Err()
case out <- *best:
last = best.name
}
} else if serverDebugLog {
console.Debugln("mergeEntryChannels: discarding duplicate", best.name, "<=", last)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/metacache-server-pool.go
Expand Up @@ -273,11 +273,11 @@ func (z *erasureServerPools) listMerged(ctx context.Context, o listPathOptions,
for _, pool := range z.serverPools {
for _, set := range pool.sets {
wg.Add(1)
results := make(chan metaCacheEntry, 100)
inputs = append(inputs, results)
innerResults := make(chan metaCacheEntry, 100)
inputs = append(inputs, innerResults)
go func(i int, set *erasureObjects) {
defer wg.Done()
err := set.listPath(listCtx, o, results)
err := set.listPath(listCtx, o, innerResults)
mu.Lock()
defer mu.Unlock()
if err == nil {
Expand Down Expand Up @@ -328,6 +328,7 @@ func (z *erasureServerPools) listMerged(ctx context.Context, o listPathOptions,
if err != nil {
return err
}

if contextCanceled(ctx) {
return ctx.Err()
}
Expand Down

0 comments on commit 2d00f7d

Please sign in to comment.