"PDO exception: php_network_getaddresses: getaddrinfo failed" after changing DNS resolvers, with DB running on AWS

In our Laravel 5.2 application, we have an AWS database setup using multiple read servers (and multiple database connections).

At night, we changed the DNS resolvers for all web servers to Google DNS (8.8.8.8 and 8.8.4.4). Then the servers started to spit:

PDOException: "PDOException" exception with the message " SQLSTATE [HY000] [2002] php_network_getaddresses: getaddrinfo failed: name or service is not known " in /home/forge/studydrive.net/releases/20170320162143/vendor/laravel/framework/src/ Illuminate / Database / Connectors / Connector.php: 55

The code in Connector.php:55 is just a PDO constructor:

 public function createConnection($dsn, array $config, array $options) { $username = Arr::get($config, 'username'); $password = Arr::get($config, 'password'); try { $pdo = new PDO($dsn, $username, $password, $options); // <== THIS ONE } catch (Exception $e) { $pdo = $this->tryAgainIfCausedByLostConnection( $e, $dsn, $username, $password, $options ); } return $pdo; } 

.Env configuration for AWS (with change of sensitive parts):

 DB_HOST=myapp-cluster.cluster-123abc.eu-west-2.rds.amazonaws.com DB_HOST_WRITE=myapp-cluster.cluster-123abc.eu-west-2.rds.amazonaws.com DB_HOST_READ=myapp-cluster.cluster-ro-123abc.eu-west-2.rds.amazonaws.com 

So it seems like PHP PDO suddenly cannot resolve the name DB_HOST .

Please note that we cannot use IP for DB_HOST , since the host name (from the AWS side) is mapped to 3 different database READ servers.

Also, before we changed the decision, everything worked fine.

Does anyone know what might cause a PDO error or how to solve it?

+7
php mysql amazon-web-services dns laravel
source share
3 answers

This is a bug in libc, according to:

https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1674733

php_network_getaddresses: getaddrinfo failed: name or service unknown ubuntu

+5
source share

As of March 20, many Ubuntu users over the Internet suddenly ran into DNS resolution problems in their applications due to a poor update pushed out by Canonical (supporting Ubuntu), which violates DNS resolution after several hours of uptime. Here's an error report that reported About the problem and its sorting:

https://bugs.launchpad.net/ubuntu/+source/eglibc/+bug/1674532

This can cause your CMS to fail to update / install plugins / install themes, failures in connecting to external APIs and / or error messages like the following:

Warning: file_get_contents (): php_network_getaddresses: getaddrinfo failed: there is no address associated with the host name The host could not be resolved: downloads.wordpress.org cURL error 6: The host could not be resolved: example.com in .... Fortunately, Canonical with since then could solve the problem, but the affected systems must be updated in order to get the fix. To do this, you will need DNS work, so if this happens, first reload your drops. After DNS resolution works as usual, run:

 sudo apt-get update sudo apt-get upgrade 

You can then check your versions to make sure you have the correct ones. This can be done with:

 # sudo dpkg -l | grep "GNU C Library" | awk '{print $3}' 

If you are using Ubuntu 16.X, you should see output similar to the following:

 # sudo dpkg -l | grep "GNU C Library" | awk '{print $3}' 2.23-0ubuntu7 2.23-0ubuntu7 2.23-0ubuntu7 

If you are using Ubuntu 14.X, you should see output similar to the following:

 # sudo dpkg -l | grep "GNU C Library" | awk '{print $3}' 2.19-0ubuntu6.11 2.19-0ubuntu6.11 

If you see older versions of these packages, you need to update them in accordance with the previous instructions to avoid this problem.

+4
source share

I also ran into this problem after restoring my instance, and I tried to restore the database snapshot. And restarting the application servers solved the problem for me. Worked like a charm! :)

0
source share

All Articles