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. 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”
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
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…

Installing MySQL Extensions for Ruby

When I tried ‘gem install mysql’, I got the following error:

ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… yes
checking for mysql_query() in -lmysqlclient… no

Here is the command I used to fix it:
‘gem install mysql — –with-include=/usr/include/mysql –with-mysql-lib=/usr/lib/mysql –with-mysql-config’
</div