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
Piccolo wrote:
nice tip - and well explained.
Posted 26 Apr 2008 at 4:53 pm ¶
Simisani Takobana wrote:
Is there a way of testing this , instead of waiting over night ?
Posted 29 Sep 2008 at 1:09 pm ¶
Rich Brant wrote:
Well, I’ve switched to Phusion Passenger whenever I’ve been able to, and I’d recommend the same to you. Then there are no Mongrel issues.. But if you really wanted to test it, you could drop both var down to really low numbers. Although, you’d have to cut off access so there was no interaction with the world and your server, too.
Posted 29 Sep 2008 at 1:58 pm ¶