Skip to content

Commit c9e1c10

Browse files
committed
🐛 Manager.Elected() should beclosed after runnables are started
During debugging a weird issue with some tests failing if they were running too fast. In other words, calling Start() and Close() on a manager too fast throws an error where the informers haven't been able to sync, which then makes Start() fail with an error. In an effort to improve this behavior, tried to use Elected() to wait for leader election to start, which also waits for the cache. During some debugging, this issue happened again and upon digging a bit more it seems that the channel was closed before starting the runnables in some cases. This change reorders the close on cm.elected, which should fix the above issue. Signed-off-by: Vince Prignano <[email protected]>
1 parent 73c52e8 commit c9e1c10

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pkg/manager/internal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) {
473473
}
474474
} else {
475475
// Treat not having leader election enabled the same as being elected.
476+
cm.startLeaderElectionRunnables()
476477
close(cm.elected)
477-
go cm.startLeaderElectionRunnables()
478478
}
479479
}()
480480

@@ -632,8 +632,8 @@ func (cm *controllerManager) startLeaderElection() (err error) {
632632
RetryPeriod: cm.retryPeriod,
633633
Callbacks: leaderelection.LeaderCallbacks{
634634
OnStartedLeading: func(_ context.Context) {
635-
close(cm.elected)
636635
cm.startLeaderElectionRunnables()
636+
close(cm.elected)
637637
},
638638
OnStoppedLeading: cm.onStoppedLeading,
639639
},

0 commit comments

Comments
 (0)