Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm looking after a rails app running Passenger, and MySQL, on a VPS running Ubuntu Intrepid and earlier this morning, the webserver stopped being able to connect to the server. My exception notifier sent me a message with this error:

ActionView::TemplateError: Mysql::Error: MySQL server has gone away: SELECT * FROM `table_name` WHERE (`table_name`.`id` = 70)

Shelling into the vps trying to open up mysql gave me this:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I cleared this error by stopping apache, rebooting the database server and restarting passenger, which seems to have everything humming along fine again, but this doesn't solve the problem of working out why this happened in the first place.

Which places should I be looking to find the cause of this error? (other than production.log, or a /var/log ), so I can avoid this in future, and seeing that this was so simple to fix, would it be worth automating a reboot of the two servers if these conditions occurred again in future?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This issue happens when MySQL database closes the persistent connection opened by your Rails app. When your Rails app stays idle for a long time (>= connection close time as defined in mysql config) with no requests hitting it, this happens.

You might want to increase the connection expiry time in mysql settings - or write a cron job to keep fetching some dynamic page from the rails app (so that rails keeps the db handle fresh).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.