views:

336

answers:

2

I have a rails app that I have serving up XML on an infrequent basis. This is being run with mongrel and mysql. I've found that if I don't exercise the app for longer than a few hours it goes dead and starts throwing Errno::EPIPE errors. It seems that the mysql connection get timed out for inactivity or something like that.

It can be restarted with 'mongrel_rails restart -P /path/to/the/mongrel.pid' ... but that's not really a solution. My collaborator expects the app to be there when he is working on his part (and I am most likely not around).

My question is:

  • What can I do to prevent this problem from occurring in the 1st place? (e.g. don't time me out!!).
  • Failing that, is there some code I can insert somewhere to automatically remake the Db connection?
+1  A: 

Here's a solution:

https://boxpanel.blueboxgrp.com/public/the_vault/index.php/Mongrel_/_MySQL_Timeout

The timeouts on the above solution seem a little high to me. You don't want your DB timeouts to be too low, because of the amount of memory a connection can use. If a connection is orphaned, you want it to time out reasonably (like not in one week.)

Chris
A: 

In other places, I also got the following suggestions:

  1. Try setting config.active_record.verification_timeout to something lower than whatever your mysql connection timeout setting is.

  2. There's a gem to work around this problem: mysql_retry_lost_connection

     http://rubyforge.org/projects/zventstools/
     "Reconnect to the MySQL server when you hit a lost connection error".
    
Mike Berrow