Skip to content

BUG: Daemon shutdown sequence has no goroutine coordination #911

@andrinoff

Description

@andrinoff

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

  1. Run daemon with multiple accounts and active IDLE watchers
  2. Send SIGTERM during a background sync
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingchoreMaintenance, refactor, cleanupneeds-responseWaiting on issue author replystaleNo activity for extended period

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions