datasetworker: skip jobs orphaned by deleted preparations#680
Merged
Conversation
c6f065e to
8f69c70
Compare
Co-Authored-By: JAG-UK <jon.geater@gmail.com>
8f69c70 to
a61d4c4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A dataset worker can nil-deref
*job.Attachmentand panic, taking down the service. Reported as a pack-side panic atpack/pack.go:91(job.Attachment.Preparation.GetMinPieceSize()), but the same shape exists at the run-loop dispatch indatasetworker.gofor all three job types -- aunified.dbfrom a user'sprep start-scanrun shows the scan path panicking with the same root cause.With
--exit-on-errorit becomes a crash loop: the panic unwinds past the normal error handler so the job's state is never written toError, and on restart the healthcheck resets the dead worker's claimed job back toReady. Same job, same panic, again.Root cause
Job/file/car associations use
OnDelete: SET NULLfor fast prep deletion with async reaping. When a preparation (or attachment) is deleted,jobs.attachment_idis nulled and the healthcheck reaper deletes those rows later, in batches of 100 every 5 minutes.findJobclaims jobs with:```go
Where("type = ? AND (state = ? OR (state = ? AND worker_id IS NULL))", ...)
```
No
attachment_id IS NOT NULLguard, so an orphaned job whose attachment was nulled but not yet reaped gets claimed. The preload then leavesjob.Attachmentnil and the dispatch --case model.Scan: w.scan(workCtx, *job.Attachment)and the equivalents forPack/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: addattachment_id IS NOT NULLso 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:TestFindWorkSkipsOrphanedJobasserts 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.