WIP: root background loops at context.Background() (refs #97)
Some checks failed
check / check (push) Failing after 1m2s
Some checks failed
check / check (push) Failing after 1m2s
Incomplete: tests pass but three lint findings remain (funcorder on registerHooks, unparam in engine_integration_test.go). Committed to preserve work in progress; to be amended into a single clean commit.
This commit is contained in:
@@ -56,9 +56,20 @@ func NewRetentionReaper(
|
||||
interval: params.Config.RetentionSweepInterval,
|
||||
}
|
||||
|
||||
r.registerHooks(lc)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// registerHooks wires the reaper's start and stop into the fx
|
||||
// lifecycle. The start hook's context is deliberately ignored: see
|
||||
// start for why the sweep loop must not inherit it.
|
||||
func (r *RetentionReaper) registerHooks(lc fx.Lifecycle) {
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
r.start(ctx)
|
||||
//nolint:contextcheck // Not inheriting the hook context is
|
||||
// the point: see start.
|
||||
OnStart: func(_ context.Context) error {
|
||||
r.start()
|
||||
|
||||
return nil
|
||||
},
|
||||
@@ -68,12 +79,20 @@ func NewRetentionReaper(
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *RetentionReaper) start(ctx context.Context) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
// start launches the background sweep loop.
|
||||
//
|
||||
// The loop's context is derived from context.Background(), NOT from
|
||||
// the fx OnStart hook context. The hook context carries fx's start
|
||||
// timeout (15s by default) and is cancelled once the start phase
|
||||
// completes, so a loop derived from it dies 45 minutes before its
|
||||
// first tick under the default one-hour sweep interval, leaving a
|
||||
// reaper that never reaps. A long-lived goroutine must outlive the
|
||||
// startup phase, so its lifetime is bounded by OnStop instead: stop
|
||||
// cancels this context and waits on the WaitGroup.
|
||||
func (r *RetentionReaper) start() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
r.cancel = cancel
|
||||
|
||||
r.wg.Add(1)
|
||||
|
||||
Reference in New Issue
Block a user