Good morning,
I have in my environment:
GKEs, Functions, Runs and I use Cloud SQL MySQL as my database.
For GKE I use private connection with SQL.
For Runs and Functions I use serverless vpc connector to make this connection between database.
For all days my system works fine, but when a receive more requests, I have a problem with communication between Runs/Functions and Database.
I yet do:
- Adjust flags in database (max_connections and wait_timeout);
- Increase troughput from serverless vpc connector;
- Adjust ports for Cloud Nat.
But, I always when receive a high requests receive a error: [ERROR] SQLSTATE[HY000] [2002] Connection refused
I open a ticket from GCP, but this spend one month I do not have any good answer, only tips that I do, like I tell before.
Is someone give this error before?
By the way: only run/functions receive this error, my gkes works fine during this errors.
Thanks,
Solved! Go to Solution.
Guys, in my case the problem was a lot open connections in php (stateless), so I migrate my framework to a new with pool connections and works fine.
This occurs because cloud run has a limitation in open sessions.
The error "SQLSTATE[HY000] [2002] Connection refused" means that the client was unable to establish a connection to the database server. This can be caused by a number of factors, including:
Serverless VPC Connector
The Serverless VPC Connector allows serverless products like Cloud Functions and Cloud Run to connect to internal resources within the VPC, including private Cloud SQL instances.
Database Configuration
When checking the configuration of the Cloud SQL MySQL database, you should pay attention to the following settings:
max_connections
: This setting limits the number of simultaneous connections to the database. If the database is reaching its connection limit, you may need to increase this setting.wait_timeout
: This setting specifies the amount of time that the server waits for activity on a non-interactive connection before closing it. If you have long-running connections that are occasionally active, consider increasing this setting.Network Infrastructure
When checking the health of the underlying network infrastructure, you should consider the following:
Permissions
Verify that the service accounts used by Cloud Functions and Cloud Run have the necessary IAM roles and permissions to connect to the Cloud SQL database.
Library Versions
Ensure that the client libraries used to connect to Cloud SQL in your Cloud Functions and Cloud Run deployments are up-to-date.
Additional Suggestions
Hi @ms4446 , thanks for your answer. But:
Another thing there is a limit of 100 open connection between one instance run and cloud sql. But, how can I see that? I think after read a lot of documentation the problem is there. But, again, how can I see this limitation?
Thanks,
I understand that you've thoroughly investigated the common causes of the issue and that only your Cloud Run and Cloud Functions services are affected. Given your use of a PHP library for Cloud SQL connections and the task enqueuing mechanism, I concur that the issue might be related to the 100 open connections limit between a Cloud Run instance and Cloud SQL.
To monitor the number of open connections to your Cloud SQL instance, consider using Cloud Monitoring. This tool can provide insights into the number of active connections over time, helping you determine if you're nearing the limit.
If you find that you're consistently reaching or exceeding this limit, consider the following:
Additional considerations:
If the issue persists, reaching out to Google Cloud Platform support for further assistance might be beneficial.
Dylan Gatt
Guys, in my case the problem was a lot open connections in php (stateless), so I migrate my framework to a new with pool connections and works fine.
This occurs because cloud run has a limitation in open sessions.