0

I have developed django with gcp cloud sql proxy not in trouble. But suddenly I can 't connect cloud sql with this message.

console message: 2019/03/15 11:48:41 Ready for new connections 2019/03/15 11:48:50 New connection for "my-project-instance" 2019/03/15 11:48:52 Reading data from local connection on 127.0.0.1:5432 had error: read tcp 127.0.0.1:5432->127.0.0.1:55125: wsarecv: An existing connection was forcibly closed by the remote host.

how can i fix this?

Maibi
  • 45
  • 1
  • 7
  • When the error is `An existing connection was forcibly closed by the remote host.`, most likely you are sending wrong request. Show the request causing error, and moreover try to catch the request detail by WireShark. – MT-FreeHK Mar 15 '19 at 03:17
  • Most likely idle connections are getting closed by the server but sql proxy doesn’t detect it until it tries to use the connection. Try adjusting TCP keepalive as mentioned in this doc: https://cloud.google.com/sql/docs/postgres/diagnose-issues – neildo Mar 15 '19 at 03:19
  • I don't use compute engine, Does keepalive value in this doc be between compute engine and cloud sql instance? I just create sql admin id with json key. but, same error. does i try to WireShark? – Maibi Mar 15 '19 at 04:16

1 Answers1

0

MySQL has a default wait_timeout value of 8 hours - any connections open for this length of time get forcibly closed.

You should use connection pooling (a great library for this in python is SQLAlchemy) and limit the connection duration to a value lower than this. You can see several examples of how to do this on the Managing Database Connections page.

kurtisvg
  • 3,412
  • 1
  • 8
  • 24
  • the sql proxy is no problem with another computer. so, my pc has a problem. but I don't have an idea. I delete some programs , but I still fail to connection. should I format my pc and re-install windows? – Maibi Mar 18 '19 at 02:33
  • I found a program troubling with cloud sql proxy. I deleted this program. the connection works. – Maibi Mar 18 '19 at 04:05
  • Do you mind sharing what program you found to be troubling cloud sql proxy..? – MTay Sep 22 '20 at 23:15