I have developed several ruby apps which are currently live in
production. Recently I have encountered a problem where my apps stop
responding after a long period of inactivity. I am using Webrick as the
server with Rails 1.1.2 and mysql 5.0.21. I have dug up other issues
people have had with mysql dropping connections after 8 hours, and the
supposed fix of adding an ActiveRecord::Base.verification_timeout value
less than the MySQL interactive_timeout value. My mysql server
interactive_timeout is set to the default 28800 seconds (8 hours) and
I’ve tried setting the active record verification_timeout to something
small like 1800 (30 mins). My understanding is that after the
verification_timeout has elapsed, active record will verify the
connection still exists before making a query to the database.
I have been getting very strange results and I’m having a hard time
making sense of it. I have been running a few different apps and after 8
hours I see that mysql drops the connections to the database. If I
attempt to request a URL from any of these apps not too long after the
mysql connections get dropped (like less than an hour), it seems to have
no problem reconnecting to the database and my app functions just fine.
But if I wait longer after the connection gets dropped (like around 3-4
hours or so) they do not reconnect to the database, and they never
return a response. The browser just sits there trying to the load the
page and eventually gets a browser message “The connection to the server
I’m running out of ideas to try. Could this possibly be a combination of
more than one problem? It definately is related to inactivity, because
if the site is accessed regularly it never stops responding. I’m
assuming the problem is a loss of connection to the database, but my
solution only seems to work in certain circumstances. Has anyone
experienced something like this, and could anyone give me some advice in
what direction I should go in solving this issue? I’ve thought about
writing a script to access a URL on the site every hour or so, but I was
hoping to come up with a more proper, elegant solution that doesn’t
require some quirky hack.
Thanks to anyone who can help me out!