dimanche 25 novembre 2018

E_WARNING: Error while sending STMT_PREPARE packet. PID=*

My Laravel app has a queue worker that runs jobs (artisan queue:work --sleep=3 --tries=3 --daemon), and the first step in the handle() function of some of my jobs is to check for the presence of a record as follows:

$conditionsToMatch = [
    'contact_id' => $contactId,
    'job_class_name' => static::class,
    'execute_at' => $executeAt->format(TT::MYSQL_DATETIME_FORMAT)
];
$automation = Automation::where($conditionsToMatch)->first();

This often causes an exception on that first() line:

E_WARNING: Error while sending STMT_PREPARE packet. PID=2091: Error while sending STMT_PREPARE packet
File "/var/www/myapp/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php", line 80
File "/var/www/myapp/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php", line 80, in PDO::prepare
File "/var/www/myapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php", line 326, in Doctrine\DBAL\Driver\PDOConnection::prepare
File "/var/www/myapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php", line 657, in Illuminate\Database\Connection::Illuminate\Database\{closure}
File "/var/www/myapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php", line 624, in Illuminate\Database\Connection::runQueryCallback
File "/var/www/myapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php", line 333, in Illuminate\Database\Connection::run
File "/var/www/myapp/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", line 2027, in Illuminate\Database\Connection::select
File "/var/www/myapp/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", line 2015, in Illuminate\Database\Query\Builder::runSelect
File "/var/www/myapp/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", line 2499, in Illuminate\Database\Query\Builder::Illuminate\Database\Query\{closure}
File "/var/www/myapp/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", line 2016, in Illuminate\Database\Query\Builder::onceWithColumns
File "/var/www/myapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php", line 516, in Illuminate\Database\Query\Builder::get
File "/var/www/myapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php", line 500, in Illuminate\Database\Eloquent\Builder::getModels
File "/var/www/myapp/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php", line 77, in Illuminate\Database\Eloquent\Builder::get
File "/var/www/myapp/app/Jobs/DispatchableWithControl.php", line 51, in Illuminate\Database\Eloquent\Builder::first

I've tried changing my MySql config to use max_allowed_packet=16M (instead of the default of 4M) but still get these exceptions occasionally.

I've seen some people (such as jpral) recommend DB::connection()->reconnect(), but that feels like it ignores whatever the root cause is. I always prefer to fully understand the root cause of a problem and address it.

Any ideas? Thanks.

P.S. The table has indexes for each of those 3 columns but not on the "soft deletes" deleted_at column, but supposedly that is appropriate.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire