Archive for June 2nd, 2009

Ruby on Rails background process: MySQL server has gone away

June 02nd, 2009 | Category: Uncategorized

Using workling and starling to handle background tasks is very nice. Check out this link for info on setting it up.  However, I encountered the error: “Mysql::Error: MySQL server has gone away” when accessing an external DB tables like users and roles.  I found that someone recommended using verify_active_connections!, however the table the connection error occurred on was a HABTM table ‘user_roles’. I found that verify_active_connections will use the scope of the model/object you invoke it on. So the final solution was to do the following:

user.roles.verify_active_connections!

This will make sure users, user_roles, and roles all have valid connections. This error occurred using rails 2.0.1. It may be fixed in newer versions of ActiveRecord.

No comments