Skip to content

datasetworker: skip jobs orphaned by deleted preparations#680

Merged
parkan merged 1 commit into
mainfrom
fix/orphan-jobs-nil-attachment
Jun 29, 2026
Merged

datasetworker: skip jobs orphaned by deleted preparations#680
parkan merged 1 commit into
mainfrom
fix/orphan-jobs-nil-attachment

Conversation

@parkan

@parkan parkan commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Problem

A dataset worker can nil-deref *job.Attachment and panic, taking down the service. Reported as a pack-side panic at pack/pack.go:91 (job.Attachment.Preparation.GetMinPieceSize()), but the same shape exists at the run-loop dispatch in datasetworker.go for all three job types -- a unified.db from a user's prep start-scan run shows the scan path panicking with the same root cause.

With --exit-on-error it becomes a crash loop: the panic unwinds past the normal error handler so the job's state is never written to Error, and on restart the healthcheck resets the dead worker's claimed job back to Ready. Same job, same panic, again.

Root cause

Job/file/car associations use OnDelete: SET NULL for fast prep deletion with async reaping. When a preparation (or attachment) is deleted, jobs.attachment_id is nulled and the healthcheck reaper deletes those rows later, in batches of 100 every 5 minutes.

findJob claims jobs with:

```go
Where("type = ? AND (state = ? OR (state = ? AND worker_id IS NULL))", ...)
```

No attachment_id IS NOT NULL guard, so an orphaned job whose attachment was nulled but not yet reaped gets claimed. The preload then leaves job.Attachment nil and the dispatch -- case model.Scan: w.scan(workCtx, *job.Attachment) and the equivalents for Pack/DagGen -- nil-derefs.

Data-state dependent, not engine dependent: reproduces on sqlite and postgres alike. A fresh DB just hides it until the next preparation deletion.

Fix

  • find.go: add attachment_id IS NOT NULL so orphaned jobs are skipped and left for the reaper. This is the primary fix.
  • datasetworker.go: defensive nil guard at the run-loop dispatch, covering Scan/Pack/DagGen uniformly. Belt-and-suspenders for any race between the SET NULL cascade and the claim+preload window.
  • find_test.go: TestFindWorkSkipsOrphanedJob asserts orphaned jobs of all three types are not claimed.

Supersedes #679 -- same primary fix, with the defensive guard moved one frame up so Scan and DagGen are covered by the same code path, not just Pack.

@parkan parkan force-pushed the fix/orphan-jobs-nil-attachment branch from c6f065e to 8f69c70 Compare June 29, 2026 10:04
@parkan parkan changed the title fix for johng reported sqlite multi case datasetworker: skip jobs orphaned by deleted preparations Jun 29, 2026
Co-Authored-By: JAG-UK <jon.geater@gmail.com>
@parkan parkan force-pushed the fix/orphan-jobs-nil-attachment branch from 8f69c70 to a61d4c4 Compare June 29, 2026 10:54
@parkan parkan merged commit 80c1414 into main Jun 29, 2026
1 check failed
@parkan parkan deleted the fix/orphan-jobs-nil-attachment branch June 29, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant