Intermittent error when accessing RDS database with PHP 7.4

0

Every 5 to 10min, our webapp (PHP 7.4 - Symfony) is experiencing an error trying to access an RDS database. We used to host our DB on a EC2 instance and it worked fine. Since the migration we have this problem.

As of today I tried :

  • Checking the connection credentials : they are correct
  • Checking if it was a DNS resolution limitation : it was not
  • Upgrade the instance type of the RDS instance : the problem is still here
  • Checked the max packets allowed by MYSQL and other such parameters : the values are the same as the old DB

Here is the error I am getting : `[2023-12-05 11:27:03] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known" at /***/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 112

{"exception":"[object] (Doctrine\DBAL\Exception\ConnectionException(code: 0): An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known at /var/www/***/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:112, Doctrine\DBAL\Driver\PDO\Exception(code: 2002):

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known at /var/www/html/clic-and-fit/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18, PDOException(code: 2002):

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known at /***/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:40, PDOException(code: 0):

PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known at /***/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:40)"} []`

EDIT : I tried to use the IP address associated with the RDS endpoint, and it seems to solve the problem. So it looks like it is a DNS issue. Either an EC2 limitation or a VPC limitation. But the thing is, I tested how many DNS requests my instance is launching each second, and it is way below the 1024 limit. So I am going to be setting up a DNS cache on my server to solve the issue.

2 Answers
0

Hello.

If you are using Symfony, why not try clearing the cache with the following command?
Please also try restarting the web server such as Apache.

php app/console cache:clear
profile picture
EXPERT
answered 5 months ago
  • Hello,

    Thank you for you answer. I tried clearing the cache, restarting PHP-FPM and Apache2 and it didn't resolve the issue

0

Whats the DB version and try checking the timeout settings on PHP and MySQL level. Updated PHP drivers to match the DB version? if you are allowing persistent connection or connection pooling, need to make sure those are not killed due to idle timeout.

Krishna
answered 5 months ago
  • I tried to use the IP address associated with the RDS endpoint, and it seems to solve the problem. So it looks like it is a DNS issue. Either an EC2 limitation or a VPC limitation. But the thing is, I tested how many DNS requests my instance is launching each second, and it is way below the 1024 limit. So I am going to be setting up a DNS cache on my server to solve the issue

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions