Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Fix config watcher stop lifecycle race

rcourtman7cebe788590d
diff --git a/docs/release-control/v6/internal/records/documentation-currentness-and-legacy-cleanup-v6-rc4-packet-2026-05-05.md b/docs/release-control/v6/internal/records/documentation-currentness-and-legacy-cleanup-v6-rc4-packet-2026-05-05.md
index 333534050e..ebab3293a5 100644
--- a/docs/release-control/v6/internal/records/documentation-currentness-and-legacy-cleanup-v6-rc4-packet-2026-05-05.md
+++ b/docs/release-control/v6/internal/records/documentation-currentness-and-legacy-cleanup-v6-rc4-packet-2026-05-05.md
@@ -141,6 +141,14 @@ committed the canonical TrueNAS host record. The test now waits for the actual
ingested TrueNAS host before stopping the poller, so the release gate proves the
canonical record instead of transport activity alone.
+The first publish release workflow exposed one more backend race in
+`TestConfigWatcher_WatchForChanges_Live`: `ConfigWatcher.Stop()` closed the
+watcher but did not wait for the fsnotify goroutine to exit, so test teardown
+could restore package-level debounce state while a background reload was still
+reading it. `ConfigWatcher` now tracks watcher and polling goroutines and joins
+them during `Stop()`, making the stop call the canonical lifecycle barrier for
+live auth-env reload teardown.
+
No public issue comment, retitle, closure, or customer-facing message was made
as part of this packet update.
@@ -164,6 +172,18 @@ as part of this packet update.
- `prepare`, `frontend_checks`, `helm_smoke`, and `docker_build` passed
- `backend_tests` failed on `TestTrueNASPollerEnableDisableCycle` stopping
before canonical TrueNAS host ingest was proved
+- Draft release workflow `25386988654`:
+ - `prepare`, `frontend_checks`, `helm_smoke`, `docker_build`,
+ `backend_tests`, `create_release`, and `validate_release_assets` passed
+ - created and validated a draft `v6.0.0-rc.4` prerelease with `139` assets
+ against annotated tag `v6.0.0-rc.4` peeling to
+ `868239a6481873dc117492efcd88a16a381b9596`
+- Publish release workflow `25390505458`:
+ - `prepare`, `frontend_checks`, `helm_smoke`, and `docker_build` passed
+ - `backend_tests` failed on a race in
+ `TestConfigWatcher_WatchForChanges_Live`
- `go test -race ./internal/config ./tests/migration ./scripts/installtests`
- `go test -race ./internal/monitoring ./internal/api`
- `go test -race ./internal/monitoring -run TestTrueNASPollerEnableDisableCycle -count=20`
+- `go test -race ./internal/config -run TestConfigWatcher_WatchForChanges_Live -count=20`
+- `go test -race ./internal/config`
diff --git a/docs/release-control/v6/internal/subsystems/security-privacy.md b/docs/release-control/v6/internal/subsystems/security-privacy.md
index d1e0ff16f0..6c16a4a46e 100644
--- a/docs/release-control/v6/internal/subsystems/security-privacy.md
+++ b/docs/release-control/v6/internal/subsystems/security-privacy.md
@@ -628,3 +628,8 @@ may consume websocket-backed revocation fan-out through
`frontend-modern/src/contexts/appRuntime.ts`, but security/privacy authority
stays in the governed API token contract. The hook must not import `@/App` or
borrow root-shell ownership as token-management authority.
+That same live auth-env reload boundary also owns watcher lifecycle cleanup:
+`internal/config/watcher.go` must not return from `ConfigWatcher.Stop()` while
+its fsnotify or polling goroutine can still read debounce or callback state.
+Stopping the watcher is the synchronization point that lets tests and runtime
+teardown restore auth/config state without racing a background reload.
diff --git a/internal/config/watcher.go b/internal/config/watcher.go
index 45e8cffeb2..154414bd6a 100644
--- a/internal/config/watcher.go
+++ b/internal/config/watcher.go
@@ -35,6 +35,7 @@ type ConfigWatcher struct {
watcher *fsnotify.Watcher
stopChan chan struct{}
stopOnce sync.Once // Ensures Stop() can only close channel once
+ wg sync.WaitGroup
lastModTime time.Time
lastEnvHash string
apiTokensLastModTime time.Time
@@ -161,11 +162,19 @@ func (cw *ConfigWatcher) Start() error {
Str("env_path", cw.envPath).
Dur("poll_interval", cw.pollInterval).
Msg("Falling back to polling for config changes")
- go cw.pollForChanges()
+ cw.wg.Add(1)
+ go func() {
+ defer cw.wg.Done()
+ cw.pollForChanges()
+ }()
return nil
}
- go cw.watchForChanges()
+ cw.wg.Add(1)
+ go func() {
+ defer cw.wg.Done()
+ cw.watchForChanges()
+ }()
log.Info().Str("env_path", cw.envPath).Str("api_tokens_path", cw.apiTokensPath).Msg("Started watching config files for changes")
return nil
}
@@ -175,7 +184,10 @@ func (cw *ConfigWatcher) Stop() {
// Use sync.Once to prevent double-close panic
cw.stopOnce.Do(func() {
close(cw.stopChan)
- cw.watcher.Close()
+ if cw.watcher != nil {
+ _ = cw.watcher.Close()
+ }
+ cw.wg.Wait()
})
}
diff --git a/internal/config/watcher_test.go b/internal/config/watcher_test.go
index c96e49068c..97f86419c8 100644
--- a/internal/config/watcher_test.go
+++ b/internal/config/watcher_test.go
@@ -84,6 +84,29 @@ func TestNewConfigWatcher_DirectoryPriority(t *testing.T) {
}
}
+func TestConfigWatcher_StopWaitsForBackgroundWorker(t *testing.T) {
+ cw := &ConfigWatcher{
+ stopChan: make(chan struct{}),
+ }
+
+ workerDone := make(chan struct{})
+ cw.wg.Add(1)
+ go func() {
+ defer cw.wg.Done()
+ <-cw.stopChan
+ time.Sleep(25 * time.Millisecond)
+ close(workerDone)
+ }()
+
+ cw.Stop()
+
+ select {
+ case <-workerDone:
+ default:
+ t.Fatal("Stop returned before watcher worker exited")
+ }
+}
+
func TestConfigWatcher_ReloadConfig(t *testing.T) {
// Setup
tempDir := t.TempDir()