Skip to content

Commit

Permalink
Merge pull request #340 from yuwenma/datarace
Browse files Browse the repository at this point in the history
fix: mockapiserver data race in create memorystorage
  • Loading branch information
k8s-ci-robot committed Jun 23, 2023
2 parents f580648 + 45aac5f commit f988556
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 f988556

Please sign in to comment.