Database connections timeout

Persistent database connections to MySQL and Redis servers don’t stay open for more than a couple of minutes before connection is dropped. This issue came up since we switched to node applications in cluster mode that keep around 30 - 50 connections open at any time. Most common error is “MySQL server has gone away” that is usually handled in application logic, but lately errors like “Lost connection to MySQL server during query” and 111 “Connection refused” started coming up, which are not handled cleanly.

Even PHP applications that keep only one non-persistent connection have random connection issues. On top of that even remote SSH to server drops occasionally.

All our servers run in SF1 region. Any ideas what would be causing these connections issues?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Sorry for the late reply. With those persistent connections it’s possible that you are running out of listeners (with all the slots full with persistent connections and the short term php ones as well new clients may be getting denied or dormant connections freed up).

I would recommend reviewing my.cnf (in /etc/mysql) to see what your max_connections variable is set to. With the persistent connections, check the wait_timeout value in case MySQL is timing out these connections when they are idle.