Henning Koch
2004-Nov-02 10:06 UTC
Broken pipe error under FastCGI and Mysql (proposed fix)
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
Henning Koch
2004-Nov-02 10:33 UTC
Re: Broken pipe error under FastCGI and Mysql (proposed fix)
I just figured the way multiThreshold works was described further down for the special case singleThreshold in the FastCGI docs. I set both thresholds to "100", which with my understanding should terminate FastCGI processes every time the instance killing policy is enforced within the process manager In case this is not going to be fixed within ActiveRecord itself, I propose mentioning the following FastCGI configuration line in the Wiki and the Rails documentation: FastCgiConfig -killInterval 300 -multiThreshold 100 -singleThreshold 100 The value for killInterval should be below your Mysql timeout. - Henning> I suspect -multiTreshold and > -singleTreshold are the keys, but the FastCGI documentation > doesn''t say anything about how these parameters actually work.-- Henning Koch http://www.paws.cx