Nick Karnik
Nick Karnik
Author

Computer Scientist | Hacker | Entrepreneur | Ex-Microsoft | YC

Share


Twitter


ERRNO::EPIPE -> Broken Pipe

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 v…

Nick KarnikNick Karnik

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):

  1. ActiveRecord::Base.verification_timeout = 14400
  2. Stale database connections should be handled gracefully
  3. Irc.freenode.net – #RubyOnRails (Totally crap when you need help!)
  4. 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…