laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.51k stars 11.02k forks source link

PDO is null when using database queue #18750

Closed lazychaser closed 7 years ago

lazychaser commented 7 years ago

Description:

I'm using Lumen and database queue in my project and I noticed that after some time workers just stop doing things. When I restart them using php artisan queue:restart (but sometimes they don't restart and I have to kill them), they continue as usual. This what log says:

[2017-04-09 18:52:33] lumen.ERROR: Error: Call to a member function beginTransaction() on null in /var/www/ads-parser/vendor/illuminate/database/Concerns/ManagesTransactions.php:108
Stack trace:
#0 /var/www/ads-parser/vendor/illuminate/database/Concerns/ManagesTransactions.php(92): Illuminate\Database\Connection->createTransaction()
#1 /var/www/ads-parser/vendor/illuminate/queue/DatabaseQueue.php(294): Illuminate\Database\Connection->beginTransaction()
#2 /var/www/ads-parser/vendor/illuminate/queue/Jobs/DatabaseJob.php(68): Illuminate\Queue\DatabaseQueue->deleteReserved('low', 22053143)
#3 /var/www/ads-parser/vendor/illuminate/queue/FailingJob.php(31): Illuminate\Queue\Jobs\DatabaseJob->delete()
#4 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(392): Illuminate\Queue\FailingJob::handle('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(PDOException))
#5 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(378): Illuminate\Queue\Worker->failJob('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(PDOException))
#6 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(321): Illuminate\Queue\Worker->markJobAsFailedIfWillExceedMaxAttempts('database', Object(Illuminate\Queue\Jobs\DatabaseJob), 1, Object(PDOException))
#7 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(295): Illuminate\Queue\Worker->handleJobException('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions), Object(PDOException))
#8 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(258): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#9 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(110): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#10 /var/www/ads-parser/vendor/illuminate/queue/Console/WorkCommand.php(100): Illuminate\Queue\Worker->daemon('database', 'highest,high,no...', Object(Illuminate\Queue\WorkerOptions))
#11 /var/www/ads-parser/vendor/illuminate/queue/Console/WorkCommand.php(83): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'highest,high,no...')
#12 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#13 /var/www/ads-parser/vendor/illuminate/container/BoundMethod.php(28): call_user_func_array(Array, Array)
#14 /var/www/ads-parser/vendor/illuminate/support/helpers.php(912): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#15 /var/www/ads-parser/vendor/illuminate/container/BoundMethod.php(86): value(Object(Closure))
#16 /var/www/ads-parser/vendor/illuminate/container/BoundMethod.php(30): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#17 /var/www/ads-parser/vendor/illuminate/container/Container.php(524): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#18 /var/www/ads-parser/vendor/illuminate/console/Command.php(182): Illuminate\Container\Container->call(Array)
#19 /var/www/ads-parser/vendor/symfony/console/Command/Command.php(262): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#20 /var/www/ads-parser/vendor/illuminate/console/Command.php(167): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#21 /var/www/ads-parser/vendor/symfony/console/Application.php(826): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /var/www/ads-parser/vendor/symfony/console/Application.php(189): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /var/www/ads-parser/vendor/symfony/console/Application.php(120): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /var/www/ads-parser/vendor/laravel/lumen-framework/src/Console/Kernel.php(84): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /var/www/ads-parser/artisan(35): Laravel\Lumen\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 {main}

Next PDOException: SQLSTATE[HY000] [2002] Connection refused in /var/www/ads-parser/vendor/illuminate/database/Connectors/Connector.php:68
Stack trace:
#0 /var/www/ads-parser/vendor/illuminate/database/Connectors/Connector.php(68): PDO->__construct('mysql:host=176....', 'auto', 'autoautoauto', Array)
#1 /var/www/ads-parser/vendor/illuminate/database/Connectors/Connector.php(43): Illuminate\Database\Connectors\Connector->createPdoConnection('mysql:host=176....', 'auto', 'autoautoauto', Array)
#2 /var/www/ads-parser/vendor/illuminate/database/Connectors/MySqlConnector.php(24): Illuminate\Database\Connectors\Connector->createConnection('mysql:host=176....', Array, Array)
#3 /var/www/ads-parser/vendor/illuminate/database/Connectors/ConnectionFactory.php(183): Illuminate\Database\Connectors\MySqlConnector->connect(Array)
#4 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}()
#5 /var/www/ads-parser/vendor/illuminate/database/Connection.php(882): call_user_func(Object(Closure))
#6 /var/www/ads-parser/vendor/illuminate/database/DatabaseManager.php(243): Illuminate\Database\Connection->getPdo()
#7 /var/www/ads-parser/vendor/illuminate/database/DatabaseManager.php(229): Illuminate\Database\DatabaseManager->refreshPdoConnections('mysql')
#8 /var/www/ads-parser/vendor/illuminate/database/DatabaseManager.php(165): Illuminate\Database\DatabaseManager->reconnect('mysql')
#9 [internal function]: Illuminate\Database\DatabaseManager->Illuminate\Database\{closure}(Object(Illuminate\Database\MySqlConnection))
#10 /var/www/ads-parser/vendor/illuminate/database/Connection.php(735): call_user_func(Object(Closure), Object(Illuminate\Database\MySqlConnection))
#11 /var/www/ads-parser/vendor/illuminate/database/Connection.php(749): Illuminate\Database\Connection->reconnect()
#12 /var/www/ads-parser/vendor/illuminate/database/Connection.php(599): Illuminate\Database\Connection->reconnectIfMissingConnection()
#13 /var/www/ads-parser/vendor/illuminate/database/Connection.php(450): Illuminate\Database\Connection->run('insert into `fa...', Array, Object(Closure))
#14 /var/www/ads-parser/vendor/illuminate/database/Connection.php(404): Illuminate\Database\Connection->statement('insert into `fa...', Array)
#15 /var/www/ads-parser/vendor/illuminate/database/Query/Processors/Processor.php(32): Illuminate\Database\Connection->insert('insert into `fa...', Array)
#16 /var/www/ads-parser/vendor/illuminate/database/Query/Builder.php(2196): Illuminate\Database\Query\Processors\Processor->processInsertGetId(Object(Illuminate\Database\Query\Builder), 'insert into `fa...', Array, NULL)
#17 /var/www/ads-parser/vendor/illuminate/queue/Failed/DatabaseFailedJobProvider.php(62): Illuminate\Database\Query\Builder->insertGetId(Array)
#18 /var/www/ads-parser/vendor/illuminate/queue/Console/WorkCommand.php(162): Illuminate\Queue\Failed\DatabaseFailedJobProvider->log('database', 'low', '{"displayName":...', 'PDOException: S...')
#19 /var/www/ads-parser/vendor/illuminate/queue/Console/WorkCommand.php(132): Illuminate\Queue\Console\WorkCommand->logFailedJob(Object(Illuminate\Queue\Events\JobFailed))
#20 /var/www/ads-parser/vendor/illuminate/events/Dispatcher.php(334): Illuminate\Queue\Console\WorkCommand->Illuminate\Queue\Console\{closure}(Object(Illuminate\Queue\Events\JobFailed))
#21 /var/www/ads-parser/vendor/illuminate/events/Dispatcher.php(199): Illuminate\Events\Dispatcher->Illuminate\Events\{closure}('Illuminate\\Queu...', Array)
#22 /var/www/ads-parser/vendor/illuminate/events/Dispatcher.php(172): Illuminate\Events\Dispatcher->dispatch('Illuminate\\Queu...', Array, false)
#23 /var/www/ads-parser/vendor/illuminate/queue/FailingJob.php(36): Illuminate\Events\Dispatcher->fire(Object(Illuminate\Queue\Events\JobFailed))
#24 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(392): Illuminate\Queue\FailingJob::handle('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(PDOException))
#25 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(378): Illuminate\Queue\Worker->failJob('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(PDOException))
#26 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(321): Illuminate\Queue\Worker->markJobAsFailedIfWillExceedMaxAttempts('database', Object(Illuminate\Queue\Jobs\DatabaseJob), 1, Object(PDOException))
#27 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(295): Illuminate\Queue\Worker->handleJobException('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions), Object(PDOException))
#28 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(258): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#29 /var/www/ads-parser/vendor/illuminate/queue/Worker.php(110): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#30 /var/www/ads-parser/vendor/illuminate/queue/Console/WorkCommand.php(100): Illuminate\Queue\Worker->daemon('database', 'highest,high,no...', Object(Illuminate\Queue\WorkerOptions))
#31 /var/www/ads-parser/vendor/illuminate/queue/Console/WorkCommand.php(83): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'highest,high,no...')
#32 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#33 /var/www/ads-parser/vendor/illuminate/container/BoundMethod.php(28): call_user_func_array(Array, Array)
#34 /var/www/ads-parser/vendor/illuminate/support/helpers.php(912): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#35 /var/www/ads-parser/vendor/illuminate/container/BoundMethod.php(86): value(Object(Closure))
#36 /var/www/ads-parser/vendor/illuminate/container/BoundMethod.php(30): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#37 /var/www/ads-parser/vendor/illuminate/container/Container.php(524): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#38 /var/www/ads-parser/vendor/illuminate/console/Command.php(182): Illuminate\Container\Container->call(Array)
#39 /var/www/ads-parser/vendor/symfony/console/Command/Command.php(262): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#40 /var/www/ads-parser/vendor/illuminate/console/Command.php(167): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#41 /var/www/ads-parser/vendor/symfony/console/Application.php(826): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#42 /var/www/ads-parser/vendor/symfony/console/Application.php(189): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#43 /var/www/ads-parser/vendor/symfony/console/Application.php(120): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#44 /var/www/ads-parser/vendor/laravel/lumen-framework/src/Console/Kernel.php(84): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#45 /var/www/ads-parser/artisan(35): Laravel\Lumen\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#46 {main}  

So it fails to restore connection.

Steps To Reproduce:

themsaid commented 7 years ago

Please report on the Lumen repository.