Skip to content

fix(sealing): don't let a cancelled task block scheduling of other tasks - #13869

Open
hmdsefi wants to merge 5 commits into
filecoin-project:masterfrom
hmdsefi:fix/sched-drop-cancelled-requests
Open

hmdsefi wants to merge 5 commits into
filecoin-project:masterfrom
hmdsefi:fix/sched-drop-cancelled-requests

Conversation

@hmdsefi

@hmdsefi hmdsefi commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Fixes #10262

Proposed Changes

  • trySched drops queued requests whose context is done before the assigner runs. Schedule has already returned ctx.Err() to their callers, so there is nothing to respond to. The new RequestQueue.RemoveCancelled does this in one pass and keeps the order of the rest.
  • LazyCtx.Val doesn't cache a failed call when the caller's context was cancelled, so the next caller calls Get again. Other errors are still cached, including a deadline from SelectorTimeout, so a slow worker still fails fast for the rest of the pass.
  • Tests and a CHANGELOG entry.

Additional Info

The assigner builds one schedWorkerCache per pass, shared by all queued tasks, and LazyCtx cached the first TaskTypes result for each worker. Selector calls use a context derived from the task's context. When a cancelled task's call came first, context canceled was cached for that worker, and every other task in the pass failed with the same getting supported worker task types error as in the issue. The cancelled request could never be assigned, so it stayed in the queue and the next pass could hit it again.

Each change alone fixes the case in the issue. Dropping requests covers tasks cancelled before a pass, and the LazyCtx change covers a task that gets cancelled while a pass is running.

LazyCtx now uses a mutex instead of sync.Once. Concurrent callers still wait for the call in progress, as before. The scheduler's worker cache is its only user.

Tests:

  • TestSchedCancelledRequestDoesNotBlockOthers runs one trySched pass with a cancelled request ahead of a live one, and a worker whose TaskTypes fails on a done context like an RPC client does. With the sched.go and getonce.go changes reverted, it logs trySched(1) req.Sel.Ok error: getting supported worker task types for both requests and neither is scheduled.
  • TestRequestQueueRemoveCancelled and the new lib/lazy tests cover the two changes separately.
  • go test ./storage/sealer/ ./lib/lazy/ passes, and golangci-lint reports no issues for both packages.

Checklist

Before you mark the PR ready for review, please make sure that:

The assigner shares one worker cache across all queued tasks in a pass,
and LazyCtx cached the first TaskTypes result for each worker. When a
cancelled task's selector call came first, context canceled was cached
and every other task in the pass failed with it. The cancelled request
also stayed in the queue, so this could repeat on every pass.

Drop requests with a done context before the assigner runs, and don't
cache a LazyCtx result when the caller's context was cancelled.

Fixes filecoin-project#10262
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📌 Triage

Development

Successfully merging this pull request may close these issues.

sched: Tasks with cancelled context break scheduling loop

1 participant