Commit 809417f
Fix crash when recording a failed execution for a job that already has one
The previous code used `create_or_find_by!` in `Job#failed_with`, passing
an `exception` object as an attribute. When a FailedExecution already
existed for the job (due to a unique constraint violation), the
`find_by!` fallback tried to use the exception object as a SQL bind
parameter, causing `TypeError: can't cast ProcessMissingError`.
This state — a job having both a ClaimedExecution and a FailedExecution
— shouldn't be possible given the transactional guarantees in
`ClaimedExecution#failed_with`, but has been observed in practice by
multiple users. When it happens, `fail_orphaned_executions` crashes on
startup, preventing Solid Queue from starting at all.
Replace `create_or_find_by!` with `create!`, rescuing RecordNotUnique
to find and update the existing FailedExecution with the new error
details. If the record disappears between the failed create and the
find (race with a concurrent retry), retry the create.
Also change the `expand_error_details_from_exception` callback from
`before_create` to `before_save` (guarded by `if: :exception`) so that
updating an existing FailedExecution with a new exception properly
serializes the error details.
Fixes #699
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 5518a4d commit 809417f
3 files changed
Lines changed: 26 additions & 2 deletions
File tree
- app/models/solid_queue
- job
- test/models/solid_queue
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
76 | 93 | | |
77 | 94 | | |
78 | 95 | | |
| |||
0 commit comments