Skip to content

Commit

Permalink
Fix worker timeout handler for null $job
Browse files Browse the repository at this point in the history
The queue worker timeout handler may be called with a null `$job` if the
timeout is reached when there is no job processing (perhaps it took too long
to fetch the next job in the worker loop). This fix checks to make sure there
is a job before attempting to mark the as failed if it will exceed the maximum
number of attempts.
  • Loading branch information
djtarazona authored Aug 1, 2019
1 parent 8e9cf54 commit 2f80319
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ protected function registerTimeoutHandler($job, WorkerOptions $options)
// process if it is running too long because it has frozen. This uses the async
// signals supported in recent versions of PHP to accomplish it conveniently.
pcntl_signal(SIGALRM, function () use ($job, $options) {
$this->markJobAsFailedIfWillExceedMaxAttempts(
$job->getConnectionName(), $job, (int) $options->maxTries, $this->maxAttemptsExceededException($job)
);
if ($job) {
$this->markJobAsFailedIfWillExceedMaxAttempts(
$job->getConnectionName(), $job, (int) $options->maxTries, $this->maxAttemptsExceededException($job)
);
}

$this->kill(1);
});
Expand Down

0 comments on commit 2f80319

Please sign in to comment.