File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -62,15 +62,19 @@ func NewManager(debugConfig *componentconfig.DebuggingConfiguration, address str
62
62
// health / debug endpoints for them. It stops when the context is cancelled.
63
63
// It will only have an effect the first time it is called.
64
64
func (m * Manager ) Start (ctx context.Context , controllers ... Controller ) error {
65
+ m .RLock ()
65
66
if m .errG != nil {
66
67
return fmt .Errorf ("manager already started" )
67
68
}
69
+ m .RUnlock ()
68
70
69
71
broadcaster := record .NewBroadcaster ()
70
72
71
73
m .once .Do (func () {
74
+ m .Lock ()
72
75
m .errG , ctx = errgroup .WithContext (ctx )
73
76
m .errGCtx = ctx
77
+ m .Unlock ()
74
78
75
79
// start controllers
76
80
if err := m .Go (controllers ... ); err != nil {
@@ -105,17 +109,19 @@ func (m *Manager) Start(ctx context.Context, controllers ...Controller) error {
105
109
106
110
// Go adds controllers into the existing manager's errgroup
107
111
func (m * Manager ) Go (controllers ... Controller ) error {
108
- if m .errG == nil {
112
+ m .RLock ()
113
+ errG := m .errG
114
+ if errG == nil {
109
115
return fmt .Errorf ("cannot add controllers to an unstarted manager" )
110
116
}
111
-
112
117
ctx := m .errGCtx
118
+ m .RUnlock ()
113
119
114
120
// start newly added controllers
115
121
for _ , c := range controllers {
116
122
c := c
117
123
m .healthzHandler .AddHealthChecker (controllerhealthz .NamedHealthChecker (c .Name (), c .HealthChecker ()))
118
- m . errG .Go (func () error {
124
+ errG .Go (func () error {
119
125
ctx , cancel := context .WithCancel (ctx )
120
126
m .Lock ()
121
127
m .cancelFuncs [c ] = cancel
You can’t perform that action at this time.
0 commit comments