mirror of
https://github.com/rancher/norman.git
synced 2025-08-27 11:28:41 +00:00
Merge pull request #198 from maxkorp/plug-watch-memory-leak
Ensure that closed watchers are always stopped
This commit is contained in:
commit
ee8e325eb5
@ -243,8 +243,9 @@ func (s *Store) realWatch(apiContext *types.APIContext, schema *types.Schema, op
|
||||
decoder := streaming.NewDecoder(framer, &unstructuredDecoder{})
|
||||
watcher := watch.NewStreamWatcher(restclientwatch.NewDecoder(decoder, &unstructuredDecoder{}))
|
||||
|
||||
watchingContext, cancelWatchingContext := context.WithCancel(apiContext.Request.Context())
|
||||
go func() {
|
||||
<-apiContext.Request.Context().Done()
|
||||
<-watchingContext.Done()
|
||||
logrus.Debugf("stopping watcher for %s", schema.ID)
|
||||
watcher.Stop()
|
||||
}()
|
||||
@ -261,6 +262,7 @@ func (s *Store) realWatch(apiContext *types.APIContext, schema *types.Schema, op
|
||||
}
|
||||
logrus.Debugf("closing watcher for %s", schema.ID)
|
||||
close(result)
|
||||
cancelWatchingContext()
|
||||
}()
|
||||
|
||||
return result, nil
|
||||
|
Loading…
Reference in New Issue
Block a user