I'm having hard time seeing what causes this error, so I'll try to explain exactly what happens and what I have here.
Laravel 7 project on shared hosting, with one cron task:
* * * * * artisan schedule:run >> /dev/null 2>&1
No Supervisor etc, so for now in ../Console/Kernel.php
's schedule
function I have:
$schedule->command('queue:restart')
->everyFiveMinutes();
$schedule->command('queue:work --daemon')
->everyMinute()
->withoutOverlapping();
$schedule->command('myapp:mycommand')->daily();
What happens is that every midnight mycommand
runs perfectly fine and it does its job. However, every night approx one hour later, something triggers 1615 error two times:
SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared
(SQL: select * from `jobs` where `queue` = default and ((`reserved_at` is null and
`available_at` <= 1604019606) or (`reserved_at` <= 1604019516)) order by `id` asc
limit 1 for update)
The error stack is quite long, from artisan(37)
to ../Illuminate/Database/Connection.php(631)
, and I'm a bit confused on how to track down this issue. After that artisan reference, all files of this stack are from laravel vendor.
I don't seem to understand what or why is happening an hour after my scheduled command, or if it even has anything to do with it.
Any ideas how to debug this better? It doesn't seem to break anything or to affect anything, but it sure is annoying.
EDIT:
As suggested, there's couple possible "fixes":
ATTR_EMULATE_PREPARES
in Laravels database config, and- raising
table_definition_cache
in database itself.
The first one leads to other issues and the latter doesn't really work in shared hosting as you'd have to request service provider to raise it more and more all the time.
I got TDC increased to 1024 and the first 24h my app was error free. However, now I once again get those same errors, even over 20 pieces per 24h. They all still comes from job queue, yet so far all my jobs has been executed successfully. But I'm really concerned about this as other people are having similar errors triggered by their own code, it would be really bad if for example some emails wouldn't leave the app becouse of this.