日曜日, 7月 04, 2010

Rails: MySql lost connection error with Mongrel


以下のようにいずれかを避けることで問題を回避することができるはずである
  1. MySQLのクライアントライブラリを使用したバイナリ版のドライバをインストールする
    sudo gem install mysql
    gem install mysql -- --with-mysql-dir=/usr/local/mysql
  2. Mongrelの使用をやめ、FastCGIなどにする
  3. MySQLのコネクションがタイムアウトしないようcron等で定期的にアクセスする


Rails: MySql lost connection error with Mongrel

Mongrel stops responding a few times per days. Restarting Mongrel helps.
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

Or to any value that is lower than the MySQL server's interactive_timeout setting. This will make sure that ActiveRecord checks the connection often enough to reset the connection.
Setting timeout to avoid bug in MySQL driver that causes Mongrel stopping to work after a long idle time

Mongrel stops responding after period of inactivity


0 件のコメント: