[Rails] Broken pipe error under FastCGI and Mysql (proposed fix)

Henning Koch henning.koch at gmx.net
Tue Nov 2 10:06:36 GMT 2004


Hi,

some time ago I asked the list:

 > I have a rails application running with FastCGI. Every
 > few hours, the application exits with a
 > "Broken pipe - /tmp/mysql.sock" error whenever it needs
 > to access the database. Restarting Apache fixes this,
 > but only for another few hours.

The answer I got from you and other sources was that some
long-lived FastCGI threads outlive the lifespan of their
established Mysql connection.

In the last days I tweaked about every FastCGI configuration
parameter there is in order to reduce the lifespan of FastCGI
threads, but to no avail. The whole list of options is at
http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiConfig
in case someone has an idea. I suspect -multiTreshold and
-singleTreshold are the keys, but the FastCGI documentation
doesn't say anything about how these parameters actually work.

I also tried setting up a cronjob that writes something to an
ActiveRecord connection every fifteen minutes in case Mysql
times out after a certain period of inactivity, but since
FastCGI threads most likely don't share a common database
connection, I suppose that wasn't such a clever idea. (Mysql
DOES close connections after eight hours with defaults on).

PROPOSED FIX: Since Rails is going to be heavily used within
a FastCGI environment, I suggest fixing the problem within
ActiveRecord itself. More specifically, before abstract_adapter.rb
raises ActiveRecord::StatementInvalid, it should check if the
caught exception was caused by a broken pipe error, and in that
case establish a new connection to the database.

Let me know what you think.

- Henning

-- 
Henning Koch
http://www.paws.cx


More information about the Rails mailing list