Laravel Sail + scheduler

75 views Asked by At

Locally I have migrated my Laravel app from Homestead to Sail. Everything works fine except the scheduler.

My Commands which make calls to the database generate these errors in the logs :

[2023-11-07 08:50:02] local.ERROR: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolution (Connection: mysql, SQL: select * from information_schema.tables where table_schema = my_database and table_name = workflows and table_type = 'BASE TABLE') {"exception":"[object] (Illuminate\\Database\\QueryException(code: 2002): SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolution (Connection: mysql, SQL: select * from information_schema.tables where table_schema = my_database and table_name = workflows and table_type = 'BASE TABLE') at /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Database/Connection.php:801)
[stacktrace]
#0 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Database/Connection.php(951): Illuminate\\Database\\Connection->runQueryCallback()
#1 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Database/Connection.php(930): Illuminate\\Database\\Connection->tryAgainIfCausedByLostConnection()
#2 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Database/Connection.php(757): Illuminate\\Database\\Connection->handleQueryException()
#3 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Database/Connection.php(407): Illuminate\\Database\\Connection->run()
#4 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Database/Connection.php(394): Illuminate\\Database\\Connection->select()
#5 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php(43): Illuminate\\Database\\Connection->selectFromWriteConnection()
#6 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(353): Illuminate\\Database\\Schema\\MySqlBuilder->hasTable()
#7 /home/vagrant/code/my_project/back/app/Console/Commands/TestCommand.php(30): Illuminate\\Support\\Facades\\Facade::__callStatic()
#8 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\\Console\\Commands\\TestCommand->handle()
#9 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#10 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#11 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod()
#12 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\\Container\\BoundMethod::call()
#13 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\\Container\\Container->call()
#14 /home/vagrant/code/my_project/back/vendor/symfony/console/Command/Command.php(326): Illuminate\\Console\\Command->execute()
#15 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Console/Command.php(180): Symfony\\Component\\Console\\Command\\Command->run()
#16 /home/vagrant/code/my_project/back/vendor/symfony/console/Application.php(1081): Illuminate\\Console\\Command->run()
#17 /home/vagrant/code/my_project/back/vendor/symfony/console/Application.php(320): Symfony\\Component\\Console\\Application->doRunCommand()
#18 /home/vagrant/code/my_project/back/vendor/symfony/console/Application.php(174): Symfony\\Component\\Console\\Application->doRun()
#19 /home/vagrant/code/my_project/back/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(201): Symfony\\Component\\Console\\Application->run()
#20 /home/vagrant/code/my_project/back/artisan(35): Illuminate\\Foundation\\Console\\Kernel->handle()
#21 {main}

The paths in the logs are showing the legacy paths from Homestead (/home/vagrant/my_project/back/...). How can this be possible ?
The new Sail path is /var/www/html/...

I'm guessing the error might comes from that incorrect paths...

Thank you.

1

There are 1 answers

10
Lajos Arpad On

Your

select * from information_schema.tables where table_schema = my_database and table_name = workflows and table_type = 'BASE TABLE'

query is incorrect, because you do not have quotes around my_database and workflows. This means that your schedulers passes these parameters without enclosing them into quotes. You will need to look into your scheduler or settings and fine-tune the query which will ultimately be generated.

EDIT:

It turns out (based on our discussion in the comment-section) that the query was actually correct, but @superfive33 was pasting it from the ORM log.

So, Temporary failure at name resolution is an error that happens when a hostname cannot be resolved into an IP address: https://tecadmin.net/resolved-temporary-failure-in-name-resolution-error-in-linux/

In such situations you need to check you internet connection (you already did so by sending this question), verify DNS settings (at /etc/resolv.conf ), check your hosts file (at /etc/hosts ) and compare them with your previous setup if it's still available. Clear DNS cache and restart the network service.

You can check whether the hostname exists via running

ping example.com 

in your terminal. You might also need to authenticate to a VPN and check whether your database location has moved. Or you moved to a different network.