Skip to content

Commit 780fdfb

Browse files
committed
🐛 Controller.Watch() should not store watches if already started
The controller internal struct holds a list of watches (as []watchDescription) when someone calls .Watch() to then start the watches and informers once we're ready to call Start(). This behavior caused a memory leak in the case Watch was called after a controller has already been started and if the source.Kind's cache was either stopped or not available any longer. The leak was caused by the watches internal slice holding on to all references to each watch ever issued (and their respective caches). Signed-off-by: Vince Prignano <[email protected]>
1 parent d6829e9 commit 780fdfb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pkg/internal/controller/controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ func (c *Controller) Watch(src source.Source, evthdler handler.EventHandler, prc
113113
}
114114
}
115115

116-
c.watches = append(c.watches, watchDescription{src: src, handler: evthdler, predicates: prct})
117116
if c.Started {
118117
c.Log.Info("Starting EventSource", "source", src)
119118
return src.Start(evthdler, c.Queue, prct...)
120119
}
121120

121+
c.watches = append(c.watches, watchDescription{src: src, handler: evthdler, predicates: prct})
122122
return nil
123123
}
124124

@@ -179,6 +179,7 @@ func (c *Controller) Start(stop <-chan struct{}) error {
179179
go wait.Until(c.worker, c.JitterPeriod, stop)
180180
}
181181

182+
c.watches = nil
182183
c.Started = true
183184
return nil
184185
}()

0 commit comments

Comments
 (0)