From 05902c7101e365f7a12628809fec1cf37f759a7b Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 3 Mar 2026 19:27:06 -0800 Subject: [PATCH] fix: use lifecycle context for job-type budget and retry backoff - Use r.ctx (cancelled on shutdown) as parent for per-job-type budget context instead of context.Background(), so in-flight work is cancelled promptly on plugin shutdown. - Replace waitForShutdownOrTimer with waitForShutdownOrCtx in retry backoff so retries respect the per-job-type budget context. Co-Authored-By: Claude Opus 4.6 --- weed/admin/plugin/plugin_scheduler.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/weed/admin/plugin/plugin_scheduler.go b/weed/admin/plugin/plugin_scheduler.go index 844428374..1fb688546 100644 --- a/weed/admin/plugin/plugin_scheduler.go +++ b/weed/admin/plugin/plugin_scheduler.go @@ -194,7 +194,7 @@ func (r *Plugin) runJobTypeIteration( if budget <= 0 { budget = defaultMaxJobTypeDuration } - ctx, cancel := context.WithTimeout(context.Background(), budget) + ctx, cancel := context.WithTimeout(r.ctx, budget) defer cancel() start := time.Now().UTC() @@ -750,8 +750,8 @@ func (r *Plugin) executeScheduledJobWithExecutor( Stage: "retry", OccurredAt: timeToPtr(time.Now().UTC()), }) - if !waitForShutdownOrTimer(r.shutdownCh, policy.RetryBackoff) { - return fmt.Errorf("plugin is shutting down") + if !waitForShutdownOrCtx(r.shutdownCh, parentCtx, policy.RetryBackoff) { + return fmt.Errorf("plugin is shutting down or context canceled") } } }