We are using laravel on EC2 and connecting to an RDS instance. Sporadically, once every two days or so there is a timeout issue on the app hosted on EC2 with an error stating
SQLState[HY000][2002] Connection timeout error
There are other posts where this is due to the wrong RDS configuration but this is not the case here. The code works well for the most part. Just fails once every two days or so. Even this is not consistent. There are very few users using the system only 2 to 3 at this point. When this connection error appears the RDS instance seems to be working normally and shows no signs of any errors. We need to reboot the EC2 server for it to work again.
All of our classes extend model and just use basic queries like
Customer::where('type', 'example')->firstOrFail();
The confusing part is that it works perfectly well most of the time but just fails sporadically. We just have 2 users using the laravel app so its not a scaling issue. Wondering if it has something to do with increasing pooling limits or connection timeouts. If nothing works we would have to build a new EC2 instance to see if this occurs there as well. We do query external API’s in some of our calls but that should technically have nothing to do with the RDS timeout.