fix: replace mutex with atomic (#20762)

This commit is contained in:
Artur Melanchyk 2024-12-13 15:02:46 +01:00 committed by GitHub
parent 86d02b17cf
commit 2b008c598b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -29,6 +29,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
jsoniter "github.com/json-iterator/go"
@ -182,8 +183,7 @@ func (o *listPathOptions) gatherResults(ctx context.Context, in <-chan metaCache
resultsDone := make(chan metaCacheEntriesSorted)
// Copy so we can mutate
resCh := resultsDone
var done bool
var mu sync.Mutex
var done atomic.Bool
resErr := io.EOF
go func() {
@ -194,9 +194,7 @@ func (o *listPathOptions) gatherResults(ctx context.Context, in <-chan metaCache
// past limit
continue
}
mu.Lock()
returned = done
mu.Unlock()
returned = done.Load()
if returned {
resCh = nil
continue
@ -250,9 +248,7 @@ func (o *listPathOptions) gatherResults(ctx context.Context, in <-chan metaCache
return func() (metaCacheEntriesSorted, error) {
select {
case <-ctx.Done():
mu.Lock()
done = true
mu.Unlock()
done.Store(true)
return metaCacheEntriesSorted{}, ctx.Err()
case r := <-resultsDone:
return r, resErr