Commit 3ece5f8
committed
Respect concurrency limits when releasing claimed executions during shutdown
When a worker gracefully shuts down, claimed executions are released back
to ready state via ClaimedExecution#release. Previously, this always used
dispatch_bypassing_concurrency_limits, which ignored whether another job
with the same concurrency key was already running.
This could cause duplicate concurrent executions in the following scenario:
1. Job A starts running with concurrency key "X" (semaphore value = 0)
2. Time passes, semaphore expires and is deleted
3. Job B with same key "X" enqueues, creates new semaphore, starts running
4. Worker running Job A receives shutdown signal
5. Job A is released via dispatch_bypassing_concurrency_limits
6. Job A goes to ready state, gets picked up by another worker
7. Both Job A and Job B now running concurrently (violates limit!)
Fix: Before releasing a job, check if any other jobs with the same
concurrency key are currently executing. If so, go through normal dispatch
which respects the concurrency policy (block or discard). If not, continue
to bypass limits for performance.
This ensures that graceful shutdown doesn't violate concurrency guarantees,
even when semaphores have expired during long-running job execution.1 parent 52b3d7b commit 3ece5f8
File tree
2 files changed
+34
-1
lines changed- app/models/solid_queue
- test/models/solid_queue
2 files changed
+34
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
82 | 88 | | |
83 | 89 | | |
84 | 90 | | |
| |||
113 | 119 | | |
114 | 120 | | |
115 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
116 | 131 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
65 | 83 | | |
66 | 84 | | |
67 | 85 | | |
| |||
0 commit comments