Skip to content

Commit

Permalink
Fixed Lack of Memory when failing a job with wrong variable passed on…
Browse files Browse the repository at this point in the history
… the method fail() (#45291)

* Fixed bug on Batchs Jobs Table

If the batch has more than 1000 errors the function Bus::findBatch() fails because the database cuts down the words when reach is limit and then the seventh argument returns null because can't be json decoded.

* Update batches.stub

* Fixed Lack of Memory when failing a job

Added validation to ensure that the $exception is a Throwable instance or is null, because if we pass another type of variable in the fail() method, the fail method enters an infinite loop until the php process crashes due to lack of memory

* Update InteractsWithQueue.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
Fairydx and taylorotwell committed Dec 14, 2022
1 parent 2181f38 commit 7469819
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Illuminate/Queue/InteractsWithQueue.php
Expand Up @@ -3,6 +3,8 @@
namespace Illuminate\Queue;

use Illuminate\Contracts\Queue\Job as JobContract;
use InvalidArgumentException;
use Throwable;

trait InteractsWithQueue
{
Expand Down Expand Up @@ -43,8 +45,12 @@ public function delete()
*/
public function fail($exception = null)
{
if ($this->job) {
$this->job->fail($exception);
if ($exception instanceof Throwable || is_null($exception)) {
if ($this->job) {
return $this->job->fail($exception);
}
} else {
throw new InvalidArgumentException('The fail method requires an instance of Throwable.');
}
}

Expand Down

0 comments on commit 7469819

Please sign in to comment.