clone45's avatar

Mystery database connectivity error.

Hello!

I'm running Lumen using Docker. Everything has been working great except today. I was making some scheduler updates in the /app/Console/Kernel.php when I noticed that my log file started filling up with items such as:

[2017-08-15 19:24:04] lumen.ERROR: PDOException: SQLSTATE[HY000] [2002] Connection refused in /app/vendor/illuminate/database/Connectors/Connector.php:68
Stack trace:
#0 /app/vendor/illuminate/database/Connectors/Connector.php(68): PDO->__construct('mysql:host=127....', 'root', 'secret', Array)
#1 /app/vendor/illuminate/database/Connectors/Connector.php(44): Illuminate\Database\Connectors\Connector->createPdoConnection('mysql:host=127....', '[login]', '[password]', Array)
#2 /app/vendor/illuminate/database/Connectors/MySqlConnector.php(24): Illuminate\Database\Connectors\Connector->createConnection('mysql:host=127....', Array, Array)
#3 /app/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 /app/vendor/illuminate/database/Connection.php(882): call_user_func(Object(Closure))
#6 /app/vendor/illuminate/database/Concerns/ManagesTransactions.php(108): Illuminate\Database\Connection->getPdo()
#7 /app/vendor/illuminate/database/Concerns/ManagesTransactions.php(92): Illuminate\Database\Connection->createTransaction()
#8 /app/vendor/illuminate/queue/DatabaseQueue.php(192): Illuminate\Database\Connection->beginTransaction()
#9 /app/vendor/illuminate/queue/Worker.php(236): Illuminate\Queue\DatabaseQueue->pop('default')
#10 /app/vendor/illuminate/queue/Worker.php(101): Illuminate\Queue\Worker->getNextJob(Object(Illuminate\Queue\DatabaseQueue), 'default')
#11 /app/vendor/illuminate/queue/Console/WorkCommand.php(100): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#12 /app/vendor/illuminate/queue/Console/WorkCommand.php(84): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#13 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#14 /app/vendor/illuminate/container/BoundMethod.php(28): call_user_func_array(Array, Array)
#15 /app/vendor/illuminate/support/helpers.php(912): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#16 /app/vendor/illuminate/container/BoundMethod.php(86): value(Object(Closure))
#17 /app/vendor/illuminate/container/BoundMethod.php(30): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#18 /app/vendor/illuminate/container/Container.php(524): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#19 /app/vendor/illuminate/console/Command.php(182): Illuminate\Container\Container->call(Array)
#20 /app/vendor/symfony/console/Command/Command.php(262): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#21 /app/vendor/illuminate/console/Command.php(167): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#22 /app/vendor/symfony/console/Application.php(826): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /app/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))
#24 /app/vendor/symfony/console/Application.php(120): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /app/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))
#26 /app/artisan(35): Laravel\Lumen\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 {main}

I don't believe that I have a cron job running, and the scheduler is set to run daily, so I'm not sure what the issue could be, or why the error seems to be happening.

Here's a portion of myh Kernel.php script:

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [

    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     *
     * This function should be called every minute.
     */
    protected function schedule(Schedule $schedule)
    {
        // \DB::insert("INSERT INTO schedule_log (created_at) VALUES (NOW())");

        $schedule->call(function () {

            \Queue::push(new \App\Jobs\LogDataCollectionStarted());

Any suggestions?

0 likes
6 replies
ederson's avatar

I am facing the same issue. I've change db_host to localhost and it so far it seems to be working but i want to wait a few days before calling a solution

ederson's avatar

I jinxed it ...... Got the same error

clone45's avatar

What's strange is that my application is working fine. Even the database calls are working. I'm really at a loss why this error is being logged periodically - every seconds or so.

ederson's avatar

I haven't faced the problem since my last post but i haven't found the cause. My guess is that it was caused by my code and not laravel. Since i made some changes to optimize my code the problem disappeared

Please or to participate in this conversation.