Describe the bug
daemon.Run() starts 4 concurrent goroutines (idleEventLoop, handleSignals, backgroundSync, acceptLoop) but has no WaitGroup or coordination during shutdown. When Shutdown() fires:
backgroundSync() may be mid-fetch when providers are closed
idleEventLoop() may process a batch while connections are torn down
- Untracked goroutines spawned by
fetchAndCache() race with cleanup
- No guarantee all goroutines finish before
Run() returns
To reproduce
- Run daemon with multiple accounts and active IDLE watchers
- Send SIGTERM during a background sync
- Race between sync goroutine and provider closure
Expected behavior
Add sync.WaitGroup to track all goroutines. Ensure Run() blocks until all goroutines complete. Cancel in-flight operations via context before closing providers.
Describe the bug
daemon.Run()starts 4 concurrent goroutines (idleEventLoop,handleSignals,backgroundSync,acceptLoop) but has no WaitGroup or coordination during shutdown. WhenShutdown()fires:backgroundSync()may be mid-fetch when providers are closedidleEventLoop()may process a batch while connections are torn downfetchAndCache()race with cleanupRun()returnsTo reproduce
Expected behavior
Add
sync.WaitGroupto track all goroutines. EnsureRun()blocks until all goroutines complete. Cancel in-flight operations via context before closing providers.