Skip to content

Commit 7469819

Browse files
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 <[email protected]>
1 parent 2181f38 commit 7469819

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Illuminate/Queue/InteractsWithQueue.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Illuminate\Queue;
44

55
use Illuminate\Contracts\Queue\Job as JobContract;
6+
use InvalidArgumentException;
7+
use Throwable;
68

79
trait InteractsWithQueue
810
{
@@ -43,8 +45,12 @@ public function delete()
4345
*/
4446
public function fail($exception = null)
4547
{
46-
if ($this->job) {
47-
$this->job->fail($exception);
48+
if ($exception instanceof Throwable || is_null($exception)) {
49+
if ($this->job) {
50+
return $this->job->fail($exception);
51+
}
52+
} else {
53+
throw new InvalidArgumentException('The fail method requires an instance of Throwable.');
4854
}
4955
}
5056

0 commit comments

Comments
 (0)