Rails: MySql lost connection error with Mongrel

Having dealt with this lost connection issue more than a few times I thought I should write down the solution.

From the Mongrel FAQs:

Q: Mongrel stops working if it’s left alone for a long time.

If you find that Mongrel stops working after a long idle time
and you’re using MySQL then you’re hitting a bug in the MySQL
driver that doesn’t properly timeout connections. What happens
is the MySQL server side of the connection times out and closes,
but the MySQL client doesn’t detect this and just sits there.

What you have to do is set:

ActiveRecord::Base.verification_timeout = 14400

*But* be sure your AR verification timout is *less* than the actual variable on your MySQL server.

at the command line run:

mysql> show variables;

You’ll see “interactive_timeout.” Now all you have to do is set your verification_timeout to a number *less* than that variable’s value. In my case, setting it to 500 (my server’s interactive_timeout is 600) did the trick. So I have:

ActiveRecord::Base.verification_timeout = 500

Comments

  1. Piccolo wrote:

    nice tip - and well explained.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*

*