Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

I am getting multiple accesses on Cloud Run, and it is unable to connect to Cloud SQL.

I configured a Cloud Run instance with a Django image of my app and a PostgreSQL database on Cloud SQL. However, after deploying to production today, the application is encountering a 500 error due to database connection issues and a high number of connections. Here is the log.

django.db.utils.OperationalError: connection to server on socket "/cloudsql/dev-brawlers-cup:us-central1:brawlers-cup/.s.PGSQL.5432" failed: server closed the connection unexpectedly
Solved Solved
0 1 138
1 ACCEPTED SOLUTION

Hi @dauid64,

Welcome to Google Cloud Community!

It looks like your Cloud Run service is hitting database connection limits, which is likely causing the 500 errors. Each Cloud Run instance can make up to 100 connections to Cloud SQL, and as your service scales, the total number of connections can quickly exceed the database’s limit. Additionally, connections may be dropped unexpectedly by Cloud SQL or the platform infrastructure.

To fix this, consider implementing a connection pool in your Django app to better manage and reuse database connections. This can help prevent excessive connections and ensure automatic reconnection when a connection drops. 

If the issue persists despite connection pooling, you may also want to check Cloud SQL's connection limits and see if they align with your application's scaling needs. If needed, you can reach out to Google Cloud Support for further assistance in diagnosing and resolving the issue.

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.

View solution in original post

1 REPLY 1

Hi @dauid64,

Welcome to Google Cloud Community!

It looks like your Cloud Run service is hitting database connection limits, which is likely causing the 500 errors. Each Cloud Run instance can make up to 100 connections to Cloud SQL, and as your service scales, the total number of connections can quickly exceed the database’s limit. Additionally, connections may be dropped unexpectedly by Cloud SQL or the platform infrastructure.

To fix this, consider implementing a connection pool in your Django app to better manage and reuse database connections. This can help prevent excessive connections and ensure automatic reconnection when a connection drops. 

If the issue persists despite connection pooling, you may also want to check Cloud SQL's connection limits and see if they align with your application's scaling needs. If needed, you can reach out to Google Cloud Support for further assistance in diagnosing and resolving the issue.

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.