# Preventing Mongrel/Mysql Errno::EPIPE exceptions

**URL:** <https://www.ruby-forum.com/t/preventing-mongrel-mysql-errno-epipe-exceptions/149634>\
**Category:** Rails\
**Created:** [September 27, 2008, 1:43am UTC](https://www.ruby-forum.com/t/preventing-mongrel-mysql-errno-epipe-exceptions/149634 "2008-09-27T01:43:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [September 27, 2008, 1:43am UTC](https://www.ruby-forum.com/t/preventing-mongrel-mysql-errno-epipe-exceptions/149634/1 "2008-09-27T01:43:43Z")

</div>

I have a rails app serving up XML on an infrequent basis. This is being  
run with mongrel and mysql. I’ve found that if the app does not get  
exercised for longer than a few hours it goes dead (“Lost Connection to  
MySQL”) and starts throwing Errno::EPIPE errors. It seems that the mysql  
connection gets timed out for inactivity or something like that.

It can be restarted with ‘mongrel\_rails restart -P  
/path/to/the/mongrel.pid’ … but that’s not really a solution. My  
collaborator expects the app to be there when he is working on his part  
(and I am most likely not around).

My question is:

What can I do to prevent this problem from occurring in the 1st place?  
(e.g. don’t time me out!!).

Failing that, is there some code I can insert somewhere to automatically  
remake the Db connection?

– Mike B.

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [September 27, 2008, 11:34am UTC](https://www.ruby-forum.com/t/preventing-mongrel-mysql-errno-epipe-exceptions/149634/2 "2008-09-27T11:34:39Z")

</div>

On Sep 27, 12:43 am, Mike B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> My question is:
> 
> What can I do to prevent this problem from occurring in the 1st place?  
> (e.g. don’t time me out!!).
> 
> Failing that, is there some code I can insert somewhere to automatically  
> remake the Db connection?

change the value of config.active\_record.verification\_timeout to  
something below whatever timeout your mysql timeout is set to.

Fred

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [September 27, 2008, 6:47pm UTC](https://www.ruby-forum.com/t/preventing-mongrel-mysql-errno-epipe-exceptions/149634/3 "2008-09-27T18:47:12Z")

</div>

Frederick C. wrote:

> change the value of config.active\_record.verification\_timeout to  
> something below whatever timeout your mysql timeout is set to.

It was also suggested elsewhere

> <https://stackoverflow.com/questions/131481/preventing-mongrel-mysql-errnoepipe-exceptions>

that I do the following:  
(full advice is at  
[https://boxpanel.blueboxgrp.com/public/the\_vault/index.php/Mongrel\_/\_MySQL\_Timeout](https://boxpanel.blueboxgrp.com/public/the_vault/index.php/Mongrel_/_MySQL_Timeout)  
)

# Set the verification timeout so that the mongrel connection won’t die

if left alone (1 week)  
ActiveRecord::Base.verification\_timeout = 604800

# Keep Connection Open

Thread.new {  
loop {  
ActiveRecord::Base.verify\_active\_connections!;  
1800.times { sleep 2 }  
}  
}.priority = -10

and also (in mysql.cnf)

# Fix for bug where mongrel doesn’t close timed-out connections: Just

don’t time out connections.  
wait\_timeout= 3456000

Why is that thread calling verify\_active\_connections! needed if  
verification\_timeout \< wait\_timeout ?  
– Mike B.
