Skip to content

Commit 20dcabd

Browse files
Fixes bug with ShouldBeUniqueUntilProcessing locks getting stuck due to Middleware (#56318)
* Fixes bug with ShouldBeUniqueUntilProcessing locks * Restore back callables * Do not unlock if job was released * Update CallQueuedHandler.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 347cc4a commit 20dcabd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Illuminate/Queue/CallQueuedHandler.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,20 @@ protected function dispatchThroughMiddleware(Job $job, $command)
115115
throw new Exception('Job is incomplete class: '.json_encode($command));
116116
}
117117

118+
$lockReleased = false;
119+
118120
return (new Pipeline($this->container))->send($command)
119121
->through(array_merge(method_exists($command, 'middleware') ? $command->middleware() : [], $command->middleware ?? []))
120-
->then(function ($command) use ($job) {
122+
->finally(function ($command) use (&$lockReleased) {
123+
if (! $lockReleased && $command instanceof ShouldBeUniqueUntilProcessing && ! $command->job->isReleased()) {
124+
$this->ensureUniqueJobLockIsReleased($command);
125+
}
126+
})
127+
->then(function ($command) use ($job, &$lockReleased) {
121128
if ($command instanceof ShouldBeUniqueUntilProcessing) {
122129
$this->ensureUniqueJobLockIsReleased($command);
130+
131+
$lockReleased = true;
123132
}
124133

125134
return $this->dispatcher->dispatchNow(

0 commit comments

Comments
 (0)