Have you ever encountered a ‘Broken Pipe’ error?
It happens when MySQL closes the open connection after 8 hours (By default) or upon restarting MySQL. I tried various solutions (None of these worked):
- ActiveRecord::Base.verification_timeout = 14400
- Stale database connections should be handled gracefully
- Irc.freenode.net – #RubyOnRails (Totally crap when you need help!)
- MySQL connection timeout setting
Finally, I tried reproducing the error in Windows and realized that it didn’t crash!
Hence, I looked into Mysql.rb code and saw the following (for rails 1.2.3, activerecord 1.15.3):
Win32 => VERSION = “4.0-ruby-0.2.6-plus-changes” VERSION = “4.0-ruby-0.2.5”
Now, here is the PATCH (required for the Linux codebase):
Go to Mysql.rb => def write(data)
Add the following to the end of the method
rescue errno = Error::CR_SERVER_LOST raise Error::new(errno, Error::err(errno)) end
And VOILA a 2 min fix for 3 days of diagnosis…