Skip to content

Commit

Permalink
fix loop variable scope issue
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Fawley <dfawley@google.com>
  • Loading branch information
dfawley committed May 16, 2023
1 parent aaf76b5 commit bc12925
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions pkg/cache/v3/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ func superset(names map[string]bool, resources map[string]types.ResourceWithTTL)
return nil
}

// CreateWatch returns a watch for an xDS request.
// CreateWatch returns a watch for an xDS request. A nil function may be
// returned if an error occurs.
func (cache *snapshotCache) CreateWatch(request *Request, streamState stream.StreamState, value chan Response) func() {
nodeID := cache.hash.ID(request.Node)

Expand Down Expand Up @@ -365,8 +366,9 @@ func (cache *snapshotCache) CreateWatch(request *Request, streamState stream.Str
if err := cache.respond(context.Background(), request, value, resources, version, false); err != nil {
cache.log.Errorf("failed to send a response for %s%v to nodeID %q: %s", request.TypeUrl,
request.ResourceNames, nodeID, err)
return nil
}
return nil
return func() {}
}
}
}
Expand All @@ -387,9 +389,10 @@ func (cache *snapshotCache) CreateWatch(request *Request, streamState stream.Str
if err := cache.respond(context.Background(), request, value, resources, version, false); err != nil {
cache.log.Errorf("failed to send a response for %s%v to nodeID %q: %s", request.TypeUrl,
request.ResourceNames, nodeID, err)
return nil
}

return nil
return func() {}
}

func (cache *snapshotCache) nextWatchID() int64 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/v3/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ func TestSnapshotCacheWatch(t *testing.T) {
func TestConcurrentSetWatch(t *testing.T) {
c := cache.NewSnapshotCache(false, group{}, logger{t: t})
for i := 0; i < 50; i++ {
i := i
t.Run(fmt.Sprintf("worker%d", i), func(t *testing.T) {
t.Parallel()
id := fmt.Sprintf("%d", i%2)
Expand All @@ -358,7 +359,6 @@ func TestConcurrentSetWatch(t *testing.T) {
Node: &core.Node{Id: id},
TypeUrl: rsrc.EndpointType,
}, streamState, value)

defer cancel()
}
})
Expand Down

0 comments on commit bc12925

Please sign in to comment.