From 27d2a690268edd05fa3928149769409d87d402e8 Mon Sep 17 00:00:00 2001 From: clawbot Date: Sun, 1 Mar 2026 14:57:02 -0800 Subject: [PATCH] fix: use context.Background() for watcher goroutine lifetime The OnStart hook previously derived the watcher's context from startCtx via context.WithoutCancel(). While WithoutCancel strips cancellation, using context.Background() makes the intent explicit: the watcher's monitoring loop must outlive the fx startup phase and is controlled solely by the cancel func called in OnStop. Closes #53 --- internal/watcher/watcher.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/watcher/watcher.go b/internal/watcher/watcher.go index 6a48ce6..6a9ae64 100644 --- a/internal/watcher/watcher.go +++ b/internal/watcher/watcher.go @@ -72,13 +72,15 @@ func New( } lifecycle.Append(fx.Hook{ - OnStart: func(startCtx context.Context) error { - ctx, cancel := context.WithCancel( - context.WithoutCancel(startCtx), - ) + OnStart: func(_ context.Context) error { + // Use context.Background() — the fx startup context + // 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 - go w.Run(ctx) + go w.Run(ctx) //nolint:contextcheck // intentionally not derived from startCtx return nil },