Search code examples
pythondjangogoogle-app-enginegoogle-cloud-sql

Cloud SQL socket open failed with error: No such file or directory


I have a Django app on App Engine that connects to a Cloud Sql server.

Recently, some of the requests started to raise the following error from MySQLdb:

OperationalError: (2062, 'Cloud SQL socket open failed with error: No such file or directory')

The error is raised sporadically so it's hard to debug.


Solution

  • Found the answer here.

    Stating from GAE 1.9.5, the number of concurrent db request per instance is limited to 12. The solution was to limit the number of concurrent requests per instance to 12, by changing app.yaml:

    automatic_scaling:
      max_concurrent_requests: 12
    

    For those who don't use GAE Modules or Automatic Scaling, the solution may be to disable concurrent requests completely by setting threadsafe: false. Note that this might dramatically increase the number of instances.

    Another solution is to use some kind of a DB connection pool with a limited number of simultaneous connections. I haven't tried it myself.