Heroku 500 error after downtime - continued :: DatabaseDisconnectError - Mysql :: Error: MySQL server is gone

I have a simple sinatra application hosted on Heroku, and using ORK Sequel to connect to the MySql database through the cleardb addon.

The application works fine, unless it has been idle for more than a minute. In this case, the first request I make gives 500 internal server errors that heroku logsshow:

sequel::DatabaseDisconnectError - Mysql::Error: MySQL server has gone away

If I refresh the page after this error, it works fine, and the error does not return until the application stops for another minute.

The application has 2 speakers running, so the problem is not caused by what you can see on the free account using the heroku recorder. I contacted cleardb support and they gave me this advice:

if you are using a connection pool, then you should set the idle timeout just below 60 seconds and / or set the keep alive, as I mentioned below. If you are not using a connection pool, then you must make sure that the application really closes the connections after requests and does not rely on the network timeout to close them.

, cron, 30 , . , , . Sequel - , Sequel . , ? ?

+4
1

, . Sequel , connection_validator :

DB.extension(:connection_validator)

docs, " , [...] , , "

+1

Source: https://habr.com/ru/post/1545103/


All Articles