Skip to content

Commit f039610

Browse files
authored
Merge pull request #80 from authzed/chore-deanonymize-field
deanonymize struct field
2 parents 0a5108f + 6811019 commit f039610

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

manager/manager.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ type Manager struct {
3030

3131
// a single errG is used for all managed controllers, including those
3232
// that are added after initialization
33-
errG *errgroup.Group
34-
errGCtx context.Context
33+
errG *errgroup.Group // GUARDED_BY(lock)
34+
errGCtx context.Context // GUARDED_BY(lock)
3535

3636
// a registry of cancel functions for each individual controller
37-
sync.RWMutex
38-
cancelFuncs map[Controller]func()
37+
lock sync.RWMutex
38+
cancelFuncs map[Controller]func() // GUARDED_BY(lock)
3939

4040
// for broadcasting events
4141
broadcaster record.EventBroadcaster
@@ -66,19 +66,19 @@ func NewManager(debugConfig *componentconfig.DebuggingConfiguration, address str
6666
// health / debug endpoints for them. It stops when the context is cancelled.
6767
// It will only have an effect the first time it is called.
6868
func (m *Manager) Start(ctx context.Context, readyc chan<- struct{}, controllers ...Controller) error {
69-
m.RLock()
69+
m.lock.RLock()
7070
if m.errG != nil {
71-
m.RUnlock()
71+
m.lock.RUnlock()
7272
return fmt.Errorf("manager already started")
7373
}
74-
m.RUnlock()
74+
m.lock.RUnlock()
7575

7676
var startErr error
7777
m.once.Do(func() {
78-
m.Lock()
78+
m.lock.Lock()
7979
m.errG, ctx = errgroup.WithContext(ctx)
8080
m.errGCtx = ctx
81-
m.Unlock()
81+
m.lock.Unlock()
8282

8383
// start controllers
8484
if err := m.Go(controllers...); err != nil {
@@ -109,12 +109,12 @@ func (m *Manager) Start(ctx context.Context, readyc chan<- struct{}, controllers
109109
<-ctx.Done()
110110
m.broadcaster.Shutdown()
111111

112-
m.Lock()
112+
m.lock.Lock()
113113
for ctrl, cancel := range m.cancelFuncs {
114114
cancel()
115115
delete(m.cancelFuncs, ctrl)
116116
}
117-
m.Unlock()
117+
m.lock.Unlock()
118118

119119
// no context passed to shutdown; the errg will block
120120
// until the server is closed
@@ -137,24 +137,24 @@ func (m *Manager) Start(ctx context.Context, readyc chan<- struct{}, controllers
137137

138138
// Go adds controllers into the existing manager's errgroup
139139
func (m *Manager) Go(controllers ...Controller) error {
140-
m.RLock()
140+
m.lock.RLock()
141141
errG := m.errG
142142
if errG == nil {
143-
m.RUnlock()
143+
m.lock.RUnlock()
144144
return fmt.Errorf("cannot add controllers to an unstarted manager")
145145
}
146146
ctx := m.errGCtx
147-
m.RUnlock()
147+
m.lock.RUnlock()
148148

149149
// start newly added controllers
150150
for _, c := range controllers {
151151
c := c
152152
m.healthzHandler.AddHealthChecker(controllerhealthz.NamedHealthChecker(c.Name(), c.HealthChecker()))
153153
errG.Go(func() error {
154154
ctx, cancel := context.WithCancel(ctx)
155-
m.Lock()
155+
m.lock.Lock()
156156
m.cancelFuncs[c] = cancel
157-
m.Unlock()
157+
m.lock.Unlock()
158158
c.Start(ctx, runtime.GOMAXPROCS(0))
159159
return nil
160160
})
@@ -171,16 +171,16 @@ func (m *Manager) Go(controllers ...Controller) error {
171171
func (m *Manager) Cancel(controllers ...Controller) {
172172
names := make([]string, 0, len(controllers))
173173
for _, c := range controllers {
174-
m.RLock()
174+
m.lock.RLock()
175175
cancel, ok := m.cancelFuncs[c]
176-
m.RUnlock()
176+
m.lock.RUnlock()
177177
if ok {
178178
cancel()
179179
}
180180
names = append(names, c.Name())
181-
m.Lock()
181+
m.lock.Lock()
182182
delete(m.cancelFuncs, c)
183-
m.Unlock()
183+
m.lock.Unlock()
184184
}
185185
m.healthzHandler.RemoveHealthChecker(names...)
186186
}

manager/manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func testController(t *testing.T, name string) Controller {
8888
func requireCancelFnCount(t *testing.T, m *Manager, count int) {
8989
t.Helper()
9090
require.Eventually(t, func() bool {
91-
m.RLock()
92-
defer m.RUnlock()
91+
m.lock.RLock()
92+
defer m.lock.RUnlock()
9393
return len(m.cancelFuncs) == count
9494
}, 100*time.Second, 10*time.Millisecond)
9595
}

0 commit comments

Comments
 (0)