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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
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.mdindex 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 actualingested TrueNAS host before stopping the poller, so the release gate proves thecanonical 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 madeas 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` stoppingbefore 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.mdindex 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 authoritystays in the governed API token contract. The hook must not import `@/App` orborrow 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.goindex 45e8cffeb2..154414bd6a 100644--- a/internal/config/watcher.go+++ b/internal/config/watcher.go@@ -35,6 +35,7 @@ type ConfigWatcher struct {watcher *fsnotify.WatcherstopChan chan struct{}stopOnce sync.Once // Ensures Stop() can only close channel once+ wg sync.WaitGrouplastModTime time.TimelastEnvHash stringapiTokensLastModTime 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 paniccw.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.goindex 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) {// SetuptempDir := t.TempDir()