fix: use context.Background() for watcher goroutine lifetime
All checks were successful
check / check (push) Successful in 31s
All checks were successful
check / check (push) Successful in 31s
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
This commit is contained in:
@@ -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
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user