Skip to content

Commit f8f5e68

Browse files
committed
fix: remove closed check when starting notification manager
1 parent 628b81c commit f8f5e68

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

coderd/notifications/manager.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ type Manager struct {
5353
success, failure chan dispatchResult
5454

5555
mu sync.Mutex // Protects following.
56-
closed bool
5756
notifier *notifier
5857

5958
runOnce sync.Once
@@ -161,11 +160,6 @@ func (m *Manager) loop(ctx context.Context) error {
161160
}()
162161

163162
m.mu.Lock()
164-
if m.closed {
165-
m.mu.Unlock()
166-
return xerrors.New("manager already closed")
167-
}
168-
169163
var eg errgroup.Group
170164

171165
m.notifier = newNotifier(ctx, m.cfg, uuid.New(), m.log, m.store, m.handlers, m.helpers, m.metrics, m.clock)
@@ -354,12 +348,13 @@ func (m *Manager) Stop(ctx context.Context) error {
354348
m.mu.Lock()
355349
defer m.mu.Unlock()
356350

357-
if m.closed {
351+
m.log.Debug(context.Background(), "graceful stop requested")
352+
353+
select {
354+
case <-m.stop:
358355
return nil
356+
default:
359357
}
360-
m.closed = true
361-
362-
m.log.Debug(context.Background(), "graceful stop requested")
363358

364359
// If the notifier hasn't been started, we don't need to wait for anything.
365360
// This is only really during testing when we want to enqueue messages only but not deliver them.

0 commit comments

Comments
 (0)