'How to debug a SQLSTATE[HY000] [2002] Operation timed out error in Laravel 8

PHP: 8.1.1
Laravel: 8.82
Nova: 3.31
MySQL: Serverless Aurora Mysql 5.7
Hosting: ECS/EC2 Linux 2

4-days ago, randomly and seemingly not linked to any specific update we started receiving the following errors in Sentry. Around 7 per hour, a small amount of our traffic and intermittent. It's coming from various routes and queries (updates, selects) and references our Serverless Aurora Mysql 5.7 connection which works correctly 99.9% of the time.

SQLSTATE[HY000] [2002] Operation timed out

Doctrine\DBAL\Driver\PDO\Exception

Any ideas or where to start debugging this would be appreciated.



Solution 1:[1]

Still not entirely sure what happened here, but cloning the Serverless Aurora Mysql 5.7 database and routing the traffic to the new one seemed to solve the issue. Possibly there is an issue building in the background, but currently, this is working.

+++++++

The above worked for us, but AWS support got back to us with the following as well.

Cloning the database fixed this for us, as per the answer above. But AWS support loosely got back to us with the following if it helps.

Our service team have provided some reasons this error could appear, but cannot be confirmed since the cluster along with it's logs, metrics, and resources have already been deleted:

  • Timeout settings on the client side
  • Timeout setting on the DB side
  • Connections have been exhausted on the DB and no new connections would be possible. Since Aurora Serverless scales automatically based on connections[1], it is possible that a scaling point[2] could not be found as connections increased which caused the max_connections to be reached.
  • Resource contention on the cluster, such as CPU. Since Aurora Serverless scales automatically based on CPU Utilization[1] as well, it is possible that a scaling point[2] could not be found as CPU Utilization increased which could lead to timeouts.

Solution 2:[2]

Having same issue right now. Not related to auto-scaling or max connections because no more then 35 connections but it seems most of connections in Sleep state up to 1 minute. It happens only last 4 days randomly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 DeDmytro