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 restart ing MySQL.

I tried various solutions (None of these worked):

1. ActiveRecord::Base.verification_timeout = 14400
2. Stale database connections should be handled gracefully
3. – #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”
Linux => 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
errno = Error::CR_SERVER_LOST
raise Error::new(errno, Error::err(errno))


And VOILA a 2 min fix for 3 days of diagnosis…



  1. Hi! I”ve been sufforing with this for days… I’ve done a ‘locate mysql.rb’ and came up with:/usr/local/src/ruby-mysql-0.2.6/mysql.rb; and/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysql.rbWhich do I patch?

  2. After going thru both files, I’m guessing it’s /usr/local/src/ruby-mysql-0.2.6/mysql.rbsince the other file I mentioned already has your patch…Is this correct? Or am I patching an already-installed file?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s