1
0
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:
Darren Shepherd 2018-09-24 09:01:17 -07:00 committed by GitHub
commit ee8e325eb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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