Skip to content

Commit 4f82545

Browse files
committed
Stop event watcher when broadcaster is shutdown
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
1 parent 0e0307c commit 4f82545

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pkg/internal/recorder/recorder.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type Provider struct {
5454
broadcasterOnce sync.Once
5555
broadcaster events.EventBroadcaster
5656
cancelSinkRecordingFunc context.CancelFunc
57+
stopWatcherFunc func()
5758
// Deprecated: will be removed in a future release. Use the broadcaster above instead.
5859
deprecatedBroadcaster record.EventBroadcaster
5960
stopBroadcaster bool
@@ -82,6 +83,7 @@ func (p *Provider) Stop(shutdownCtx context.Context) {
8283
p.lock.Lock()
8384
broadcaster.Shutdown()
8485
p.cancelSinkRecordingFunc()
86+
p.stopWatcherFunc()
8587
deprecatedBroadcaster.Shutdown()
8688
p.stopped = true
8789
p.lock.Unlock()
@@ -122,7 +124,7 @@ func (p *Provider) getBroadcaster() (record.EventBroadcaster, events.EventBroadc
122124
return
123125
}
124126

125-
_, err := p.broadcaster.StartEventWatcher(func(event runtime.Object) {
127+
stopWatcher, err := p.broadcaster.StartEventWatcher(func(event runtime.Object) {
126128
e, isEvt := event.(*eventsv1.Event)
127129
if isEvt {
128130
p.logger.V(1).Info(e.Note, "type", e.Type, "object", e.Related, "action", e.Action, "reason", e.Reason)
@@ -131,6 +133,8 @@ func (p *Provider) getBroadcaster() (record.EventBroadcaster, events.EventBroadc
131133
if err != nil {
132134
p.logger.Error(err, "error starting event watcher for broadcaster")
133135
}
136+
137+
p.stopWatcherFunc = stopWatcher
134138
})
135139

136140
return p.deprecatedBroadcaster, p.broadcaster

0 commit comments

Comments
 (0)