Skip to content

Commit

Permalink
fix: mockapiserver data race in create memorystorage
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwenma committed Jun 23, 2023
1 parent 9a41055 commit 41b9817
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions mockkubeapiserver/memorystorage_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ func (r *resourceStorage) watch(ctx context.Context, opt WatchOptions, callback

// TODO: Only send list if no rv specified?

// TODO: Locking on r.objects

r.mutex.Lock()
for _, obj := range r.objects {
if opt.Namespace != "" {
if obj.GetNamespace() != opt.Namespace {
Expand All @@ -77,13 +76,12 @@ func (r *resourceStorage) watch(ctx context.Context, opt WatchOptions, callback
klog.Warningf("error sending backfill watch notification; stopping watch: %v", err)

// remove watch from list
r.mutex.Lock()
r.watches[pos] = nil
r.mutex.Unlock()

return err
}
}
r.mutex.Unlock()

return <-w.errChan
}
Expand Down

0 comments on commit 41b9817

Please sign in to comment.