Skip to content

Fix race when stopping chunks memcached client #4511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 14, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/chunk/cache/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ func NewMemcached(cfg MemcachedConfig, client MemcachedClient, name string, reg
batchID: input.batchID,
}
res.found, res.bufs, res.missed = c.fetch(input.ctx, input.keys)
input.resultCh <- res
// No-one will be reading from resultCh if we were asked to quit
// during the fetch, so check again before writing to it.
select {
case <-c.quit:
return
default:
input.resultCh <- res
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sending on the channel inside the default case seems that it could still block if it enters the default clause just before quit is closed.
Can we make it a case instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry was on vacation. Very good point; done.

}
}
}
}()
Expand Down Expand Up @@ -214,7 +221,6 @@ loopResults:
results[result.batchID] = result
}
}
close(resultsCh)

for _, result := range results {
if result == nil {
Expand Down