8000 fix: remove error log when notification manager is already closed by ethanndickson · Pull Request #18264 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

fix: remove error log when notification manager is already closed #18264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 6, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
silence manager already closed error logs
  • Loading branch information
ethanndickson committed Jun 6, 2025
commit 116e9c2427e44d1e2c5d9bbdffac10ddea8ac615
19 changes: 15 additions & 4 deletions coderd/notifications/manager.go
884D
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Manager struct {
success, failure chan dispatchResult

mu sync.Mutex // Protects following.
closed bool
notifier *notifier

runOnce sync.Once
Expand Down Expand Up @@ -134,6 +135,8 @@ func (m *Manager) WithHandlers(reg map[database.NotificationMethod]Handler) {
m.handlers = reg
}

var ErrManagerAlreadyClosed = xerrors.New("manager already closed")

// Run initiates the control loop in the background, which spawns a given number of notifier goroutines.
// Manager requires system-level permissions to interact with the store.
// Run is only intended to be run once.
Expand All @@ -145,7 +148,11 @@ func (m *Manager) Run(ctx context.Context) {
go func() {
err := m.loop(ctx)
if err != nil {
m.log.Error(ctx, "notification manager stopped with error", slog.Error(err))
if xerrors.Is(err, ErrManagerAlreadyClosed) {
m.log.Warn(ctx, "notification manager stopped with error", slog.Error(err))
} else {
m.log.Error(ctx, "notification manager stopped with error", slog.Error(err))
}
}
}()
})
Expand All @@ -160,6 +167,11 @@ func (m *Manager) loop(ctx context.Context) error {
}()

m.mu.Lock()
if m.closed {
m.mu.Unlock()
return ErrManagerAlreadyClosed
}

var eg errgroup.Group

m.notifier = newNotifier(ctx, m.cfg, uuid.New(), m.log, m.store, m.handlers, m.helpers, m.metrics, m.clock)
Expand Down Expand Up @@ -348,11 +360,10 @@ func (m *Manager) Stop(ctx context.Context) error {
m.mu.Lock()
defer m.mu.Unlock()

select {
case <-m.stop:
if m.closed {
return nil
default:
}
m.closed = true

m.log.Debug(context.Background(), "graceful stop requested")

Expand Down
Loading
0