honor canceled context and do not leak on mergeChannels (#15034)

mergeEntryChannels has the potential to perpetually
wait on the results channel, context might be closed
and we did not honor the caller context canceling.
This commit is contained in:
Harshavardhana
2022-06-03 05:59:02 -07:00
committed by GitHub
parent 20a753e2e5
commit c3e1da8e04
2 changed files with 10 additions and 5 deletions

View File

@@ -695,8 +695,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)
}