cloud-sql-proxy: Occasional errors connecting to the cloudsql proxy

In my cloudsql logs I frequently see errors like this:

E  2018/06/27 06:18:50 New connection for "myproject:region:db"
E  2018/06/27 06:18:51 Client closed local connection on 127.0.0.1:5432

And in my application logs I see this:

OperationalError at /url
could not connect to server: Connection refused
        Is the server running on host "127.0.0.1" and accepting
        TCP/IP connections on port 5432?

I’m not really sure how to go about troubleshooting this. This error doesn’t happen consistently, seems to happen in bursts of 10-15 a few times a day.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 8
  • Comments: 21 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@elmarti we eventually had to give up on using the proxy and establish direct connections using the private IP. Performance has increased significantly at the expense of not encrypting traffic via proxy

Thank you for the information and the quick answer @enocom. I am very new at CloudSQL. I wanted to raise the problem since you have asked if this issue persists or not. I thought it could be related. As you mention, if the connection initiation and termination logs are info level logs then it is okay.

In one of our environments, our system works without a problem but with the same system infrastructure in a different project (that uses GCP infrastructure), we have the same connection problem same as this which is dropping the connection occasionally (in random times) and cannot continue to communicate again from that point. This led to the same connection initiation and termination logs multiple times in a row.

You are right, the problem could be related to the application side. After ensuring it is not, I will create another issue that will include our infrastructure detail and the error detail.

I’m seeing the exact same situation as @markvincze. In a 30s load test, I’ll see loads of New connection for... despite using connection pooling in the code. This, plus the added overhead of establishing new connections that Cloud Proxy introduces means that I can’t even max out the low cpu/memory limits I have on my pods before starting to get status 500 from my services due to DB connection issues.

Edit: Forgot to mention currently using 1.17