Skip to content

Commit d529bc7

Browse files
committed
Cancel summarizer context on Stop to ensure goroutine exits
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
1 parent f10a875 commit d529bc7

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

pkg/summary/client/simple.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (c *summaryResourceClient) Watch(ctx context.Context, opts metav1.ListOptio
9494
err error
9595
)
9696

97+
ctx, cancel := context.WithCancel(ctx)
9798
eventChan := make(chan watch.Event)
9899

99100
if c.namespace == "" {
@@ -107,7 +108,6 @@ func (c *summaryResourceClient) Watch(ctx context.Context, opts metav1.ListOptio
107108

108109
go func() {
109110
defer close(eventChan)
110-
defer resp.Stop()
111111
for event := range resp.ResultChan() {
112112
// don't encode status objects
113113
if _, ok := event.Object.(*metav1.Status); !ok {
@@ -123,19 +123,26 @@ func (c *summaryResourceClient) Watch(ctx context.Context, opts metav1.ListOptio
123123

124124
return &watcher{
125125
Interface: resp,
126+
cancel: cancel,
126127
eventChan: eventChan,
127128
}, nil
128129
}
129130

130131
type watcher struct {
131132
watch.Interface
133+
cancel context.CancelFunc
132134
eventChan chan watch.Event
133135
}
134136

135137
func (w watcher) ResultChan() <-chan watch.Event {
136138
return w.eventChan
137139
}
138140

141+
func (w watcher) Stop() {
142+
w.cancel()
143+
w.Interface.Stop()
144+
}
145+
139146
func generateSummarizeOpts(schema *schemas.Schema) *summary.SummarizeOptions {
140147
hasObservedGeneration := false
141148
if schema != nil && schema.Attributes != nil {

0 commit comments

Comments
 (0)