Skip to content

Commit 0aa6d7b

Browse files
committed
Ensuring done channel cannot be closed twice
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent 0107ad1 commit 0aa6d7b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

coderd/notifications/manager.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type Manager struct {
5454

5555
runOnce sync.Once
5656
stopOnce sync.Once
57+
doneOnce sync.Once
5758
stop chan any
5859
done chan any
5960

@@ -153,9 +154,9 @@ func (m *Manager) Run(ctx context.Context) {
153154
// events, creating a notifier, and publishing bulk dispatch result updates to the store.
154155
func (m *Manager) loop(ctx context.Context) error {
155156
defer func() {
156-
if m.notifier != nil {
157+
m.doneOnce.Do(func() {
157158
close(m.done)
158-
}
159+
})
159160
m.log.Info(context.Background(), "notification manager stopped")
160161
}()
161162

@@ -366,7 +367,9 @@ func (m *Manager) Stop(ctx context.Context) error {
366367
// If the notifier hasn't been started, we don't need to wait for anything.
367368
// This is only really during testing when we want to enqueue messages only but not deliver them.
368369
if m.notifier == nil {
369-
close(m.done)
370+
m.doneOnce.Do(func() {
371+
close(m.done)
372+
})
370373
} else {
371374
m.notifier.stop()
372375
}

site/src/pages/DeploySettingsPage/Sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import NotificationsIcon from "@mui/icons-material/NotificationsNoneOutlined";
77
import Globe from "@mui/icons-material/PublicOutlined";
88
import ApprovalIcon from "@mui/icons-material/VerifiedUserOutlined";
99
import VpnKeyOutlined from "@mui/icons-material/VpnKeyOutlined";
10+
import { FeatureStageBadge } from "components/FeatureStageBadge/FeatureStageBadge";
1011
import { GitIcon } from "components/Icons/GitIcon";
1112
import {
1213
Sidebar as BaseSidebar,
1314
SidebarNavItem,
1415
} from "components/Sidebar/Sidebar";
1516
import { useDashboard } from "modules/dashboard/useDashboard";
1617
import type { FC } from "react";
17-
import { FeatureStageBadge } from "components/FeatureStageBadge/FeatureStageBadge";
1818

1919
export const Sidebar: FC = () => {
2020
const { experiments } = useDashboard();

0 commit comments

Comments
 (0)