fix: use context.Background() for watcher goroutine lifetime #63

Merged
sneak merged 2 commits from fix/issue-53-startup-context into main 2026-03-02 00:39:09 +01:00

View File

@@ -72,13 +72,15 @@ func New(
} }
lifecycle.Append(fx.Hook{ lifecycle.Append(fx.Hook{
OnStart: func(startCtx context.Context) error { OnStart: func(_ context.Context) error {
ctx, cancel := context.WithCancel( // Use context.Background() — the fx startup context
context.WithoutCancel(startCtx), // expires after startup completes, so deriving from it
) // would cancel the watcher immediately. The watcher's
// lifetime is controlled by w.cancel in OnStop.
ctx, cancel := context.WithCancel(context.Background())
w.cancel = cancel w.cancel = cancel
go w.Run(ctx) go w.Run(ctx) //nolint:contextcheck // intentionally not derived from startCtx
return nil return nil
}, },