From 746981983a4090e61d4b4328cd6ab17b5279b1a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ribeiro?= Date: Wed, 14 Dec 2022 14:55:09 +0000 Subject: [PATCH] Fixed Lack of Memory when failing a job with wrong variable passed on 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 --- src/Illuminate/Queue/InteractsWithQueue.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Queue/InteractsWithQueue.php b/src/Illuminate/Queue/InteractsWithQueue.php index f7c28fd0605d..120a22458e03 100644 --- a/src/Illuminate/Queue/InteractsWithQueue.php +++ b/src/Illuminate/Queue/InteractsWithQueue.php @@ -3,6 +3,8 @@ namespace Illuminate\Queue; use Illuminate\Contracts\Queue\Job as JobContract; +use InvalidArgumentException; +use Throwable; trait InteractsWithQueue { @@ -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.'); } }