Skip to content

Commit

Permalink
Hold a read lock while canceling a snapshot watch.
Browse files Browse the repository at this point in the history
Since canceling a watch only modified the corresponding statusInfo, we
don't need to hold a write lock on the snapshot cache. Holding a read
lock is sufficient to ensure that the status entry is stable.

This updates envoyproxy#503.

Signed-off-by: James Peach <[email protected]>
  • Loading branch information
jpeach committed Oct 21, 2021
1 parent 5284181 commit 8573f90
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 @@ -335,8 +335,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 @@ -477,8 +477,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 8573f90

Please sign in to comment.