DefectiveCode / laravel-sqs-extended

Laravel SQS extended is a Laravel queue driver that was designed to work around the AWS SQS 256KB payload size limits. This queue driver will automatically serialize large payloads to a disk (typically S3) and then unserialize them at run time.
MIT License
0 stars 0 forks source link

[Bug]: Cannot assign null to property DefectiveCode\LaravelSqsExtended\SqsDiskJob::$cachedRawBody of type string #4

Open Orrison opened 3 months ago

Orrison commented 3 months ago

What happened?

We are seeing some random errors due to issues with DefectiveCode\LaravelSqsExtended\SqsDiskJob::$cachedRawBody. Details below:

TypeError: Cannot assign null to property DefectiveCode\LaravelSqsExtended\SqsDiskJob::$cachedRawBody of type string
#20 /vendor/defectivecode/laravel-sqs-extended/src/SqsDiskBaseJob.php(81): DefectiveCode\LaravelSqsExtended\SqsDiskJob::getRawBody
#19 /vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(268): Illuminate\Queue\Jobs\Job::payload
#18 /vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(318): Illuminate\Queue\Jobs\Job::timeout
#17 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(260): Illuminate\Queue\Worker::timeoutForJob
#16 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(237): Illuminate\Queue\Worker::registerTimeoutHandler
#15 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(167): Illuminate\Queue\Worker::daemon
#14 /vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(137): Illuminate\Queue\Console\WorkCommand::runWorker
#13 /vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(120): Illuminate\Queue\Console\WorkCommand::handle
#12 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}
#11 /vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\Util::unwrapIfClosure
#10 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\BoundMethod::callBoundMethod
#9 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::call
#8 /vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\Container\Container::call
#7 /vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\Console\Command::execute
#6 /vendor/symfony/console/Command/Command.php(326): Symfony\Component\Console\Command\Command::run
#5 /vendor/laravel/framework/src/Illuminate/Console/Command.php(180): Illuminate\Console\Command::run
#4 /vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Application::doRunCommand
#3 /vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application::doRun
#2 /vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application::run
#1 /vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(201): Illuminate\Foundation\Console\Kernel::handle
#0 /artisan(35): null

This seems to happen out of nowhere as the queue is running.

How to reproduce the bug

It seems difficult to reproduce. It just seems to happen randomly while the queue is running.

Package Version

1.0.0

PHP Version

8.2.0

Which operating systems does with happen with?

Linux

Notes

No response

Orrison commented 2 months ago

@SimplyCorey tagging for visibility. Seeing this error thousands of times now. Do you have any insight into what could be happening here?

SimplyCorey commented 2 months ago

@Orrison Sorry, I didn't see this. Is this happening for a single type of job or is it random? What version of Laravel are you using?

Orrison commented 2 months ago

@SimplyCorey no problem! It is difficult to tell as the error makes it hard to track down exactly which job this is failing for. After some observation, it seems to be throwing this error for a job triggered by a queued listener in this package: https://github.com/owen-it/laravel-auditing/blob/master/src/Listeners/ProcessDispatchAudit.php

We are using Laravel v10.48.20

Orrison commented 2 weeks ago

Hey @SimplyCorey I just wanted to let you know that I figured this one out. It turns out the issue was between our usage of your package and https://github.com/spatie/laravel-multitenancy, where we are switching the filesystem root per Tenant. So a job gets dispatched and puts the payload in the tenant's root in S3, but then when your package tries to load the payload, it fails to find it, as that happens before tenant switching where the root would be corrected.

So in our project I am now overriding a few of your classes and mingling in some Multitenancy things to do the Tenant finding and switching right after the item is popped out of the queue.

I of course understand that this is probably way out of the scope of your package, so we are fine maintaining our overrides. But if you are at all interested in discussing working this fix, or something like it, directly into the package just let me know and I would be more than happy to work with you on it.

Our project is source available, so you can see the PR here: https://github.com/canyongbs/advisingapp/pull/1104