Skip to content

Commit

Permalink
Hold a read lock while canceling a snapshot watch. (#507)
Browse files Browse the repository at this point in the history
Holding a read lock is sufficient to ensure that the status entry is stable when cancelling watches

This updates #503.

Signed-off-by: James Peach <[email protected]>
  • Loading branch information
jpeach authored Oct 25, 2021
1 parent 32c756f commit 67cd1a1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/cache/v3/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ func (cache *snapshotCache) nextWatchID() int64 {
func (cache *snapshotCache) cancelWatch(nodeID string, watchID int64) func() {
return func() {
// uses the cache mutex
cache.mu.Lock()
defer cache.mu.Unlock()
cache.mu.RLock()
defer cache.mu.RUnlock()
if info, ok := cache.status[nodeID]; ok {
info.mu.Lock()
delete(info.watches, watchID)
Expand Down Expand Up @@ -506,8 +506,8 @@ func (cache *snapshotCache) nextDeltaWatchID() int64 {
// cancellation function for cleaning stale delta watches
func (cache *snapshotCache) cancelDeltaWatch(nodeID string, watchID int64) func() {
return func() {
cache.mu.Lock()
defer cache.mu.Unlock()
cache.mu.RLock()
defer cache.mu.RUnlock()
if info, ok := cache.status[nodeID]; ok {
info.mu.Lock()
delete(info.deltaWatches, watchID)
Expand Down

0 comments on commit 67cd1a1

Please sign in to comment.