When I ran locally python3 manage.py runserver
from one terminal, and from another terminal is the auth proxy.
django.db.utils.OperationalError: connection to server at "127.0.0.1", port 5432
failed: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Out of nowhere when I try to connect to the Cloud SQL using auth proxy I get the below error: cloud_sql_proxy -instances=gcloud-xx-yz:europe-west3:mydb=tcp:5432
I tried with the latest version of auth proxy but had no luck, same issue. I know it is pretty stupid trying with the latest version but it does not hurt to try it at least.
2023/06/19 21:44:02 Listening on 127.0.0.1:5432 for gcloud-xx-yz:europe-west3:mydb
2023/06/19 21:44:02 Ready for new connections
2023/06/19 21:44:02 Generated RSA key in 122.002994ms
2023/06/19 21:44:18 New connection for "gcloud-xx-yz:europe-west3:mydb"
2023/06/19 21:44:18 refreshing ephemeral certificate for instance gcloud-xx-yz:europe-west3:mydb
2023/06/19 21:44:19 Scheduling refresh of ephemeral certificate in 54m59.590187s
2023/06/19 21:44:19 couldn't connect to "gcloud-xx-yz:europe-west3:mydb": read tcp 172.30.21.57:57791->xx.xx.xx.xx:3307: read: connection reset by peer
I have no clue where this IP is coming from 172.30.21.57
. This is not the ip from VPC (Not the CIDR range I am using at least) nor from my local computer.
I tried with --private-ip
but the same issue pops up.
I read about Occasionally outbound connections will be reset due to infrastructure updates
from this link but I do not think this is the issue in my case.
I basically ran out of ideas to resolve this. I read a lot about resolving this issue but could not get anywhere. Apparently, the issue is that I can not talk to CloudSQL from my local development environment. Note that, for the same app, I did use auth proxy a few dozen times, if not a hundred times, never saw this issue before. I would appreciate it if you can guide me in the right direction, or if you need more info please I am ready to update the question.
Note that the same database I used for GKE AutoPilot with workload identity (to run cloud auth proxy as sidecar with my application container) worked fine. Using a cloud shell I am able to connect to the database, allowing my home IP I can connect to the database but from the Django app, it does not work. I am using Postgres 14, and Django 3.2