# "MySQL server has gone away" with Apache 2.2 + Mongrel clust

**URL:** <https://www.ruby-forum.com/t/mysql-server-has-gone-away-with-apache-2-2-mongrel-clust/71669>\
**Category:** Rails\
**Created:** [October 10, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/mysql-server-has-gone-away-with-apache-2-2-mongrel-clust/71669 "2006-10-10T17:41:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![erubin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@erubin](https://www.ruby-forum.com/u/erubin)\
**Post date:** [October 10, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/mysql-server-has-gone-away-with-apache-2-2-mongrel-clust/71669/1 "2006-10-10T17:41:46Z")

</div>

Hi

I just setup a server (Apache 2.2, mod\_proxy\_balancer, mongrel\_cluster)  
with  
2 Rails applications according to this excellent Post:  
[http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you](http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you)

Everythings works great, but after a long inactive period (say one  
night),  
the first 3 connections allways get an Error 500

Excerpt from production.log:  
…  
Rendering authentication/login  
Completed in 0.00301 (332 reqs/sec) | Rendering: 0.00279 (92%) | DB:  
0.00000(0%) | 200 OK  
[[http://myapp/authentication/login](http://myapp/authentication/login) ]  
Mysql::Error: MySQL server has gone away: SELECT \* FROM sessions WHERE  
(session\_id = ‘875b6a6dff4de7e8bb2f7709cf9c31db’) LIMIT 1  
…

Note: the mongrel cluster is configured to have 3 mongrel processes. Is  
this a clue why only the first 3 connections allways get the error ?

Thanks for your input.

---

<div class="post-metadata">

**Author:** ![erubin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@erubin](https://www.ruby-forum.com/u/erubin)\
**Post date:** [October 10, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/mysql-server-has-gone-away-with-apache-2-2-mongrel-clust/71669/2 "2006-10-10T18:01:51Z")

</div>

what version of MySQL are you running?

ed

On 10/10/06, Eric R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Note: the mongrel cluster is configured to have 3 mongrel processes. Is  
> this a clue why only the first 3 connections allways get the error ?
> 
> Thanks for your input.
> 
> >

–  
Ed Hickey  
Developer  
Litmus Media  
816-533-0409  
removed\_email\_address@domain.invalid  
A Member of Think Partnership, Inc  
[www.ThinkPartnership.com](http://www.ThinkPartnership.com)  
Amex ticker symbol: THK

---

<div class="post-metadata">

**Author:** ![erubin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@erubin](https://www.ruby-forum.com/u/erubin)\
**Post date:** [October 10, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/mysql-server-has-gone-away-with-apache-2-2-mongrel-clust/71669/3 "2006-10-10T18:13:56Z")

</div>

> Everythings works great, but after a long inactive period (say one night),  
> the first 3 connections allways get an Error 500

Did you “gem install mysql” the latest version of the mysql gem? That  
always seems to clear up my mysql issues.

---

<div class="post-metadata">

**Author:** ![erubin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@erubin](https://www.ruby-forum.com/u/erubin)\
**Post date:** [October 10, 2006, 6:17pm UTC](https://www.ruby-forum.com/t/mysql-server-has-gone-away-with-apache-2-2-mongrel-clust/71669/4 "2006-10-10T18:17:59Z")

</div>

On Debian Sarge:  
dpkg --list | grep mysql  
ii libdbd-mysql-p 2.9006-1 A Perl5 database interface to the  
MySQL data  
ii libmysqlclient 3.23.56-3 LGPL-licensed client library for  
MySQL datab  
ii libmysqlclient 3.23.56-3 LGPL-licensed client development  
files for M  
ii libmysqlclient 4.0.24-10sarge mysql database client library  
ii libmysqlclient 4.1.11a-4sarge mysql database client library  
ii mysql-client-4 4.1.11a-4sarge mysql database client binaries  
ii mysql-common-4 4.1.11a-4sarge mysql database common files (e.g.  
/etc/mysql  
ii mysql-server-4 4.1.11a-4sarge mysql database server binaries

---

<div class="post-metadata">

**Author:** ![erubin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@erubin](https://www.ruby-forum.com/u/erubin)\
**Post date:** [October 10, 2006, 7:02pm UTC](https://www.ruby-forum.com/t/mysql-server-has-gone-away-with-apache-2-2-mongrel-clust/71669/5 "2006-10-10T19:02:19Z")

</div>

I dont know what the latest mysql gem version is.  
However, gem list --local shows mysql (2.7)

---

<div class="post-metadata">

**Author:** ![erubin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@erubin](https://www.ruby-forum.com/u/erubin)\
**Post date:** [October 10, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/mysql-server-has-gone-away-with-apache-2-2-mongrel-clust/71669/6 "2006-10-10T18:19:35Z")

</div>

MySQL times out connections after a period of inactivity. (see  
[http://dev.mysql.com/doc/refman/5.0/en/gone-away.html](http://dev.mysql.com/doc/refman/5.0/en/gone-away.html)) I think the  
period defaults to 8 hours. You can see the same behavior if you open a  
connection using the “mysql” command-line client, and leave it inactive  
for a long time. The next query will fail at first (but the client  
automatically reconnects).

Apparently, there are system variables (wait\_timeout and  
interactive\_timeout) that you can set to increase the timeout. I’ve  
never had to do this from Rails, though, so I’m not sure of the  
procedure. In our case, we have a monitoring script that hits our site  
and database periodically to make sure it’s all still up, and that has  
the side effect of keeping the mysql connections alive.

Daniel A.  
[Zoodango.com](http://Zoodango.com)

Eric R. wrote:

> Everythings works great, but after a long inactive period (say one  
> night),  
> the first 3 connections allways get an Error 500
> 
> Excerpt from production.log:  
> …  
> Rendering authentication/login  
> Completed in 0.00301 (332 reqs/sec) | Rendering: 0.00279 (92%) | DB:  
> 0.00000(0%) | 200 OK  
> [[http://myapp/authentication/login](http://myapp/authentication/login) ]  
> Mysql::Error: MySQL server has gone away: SELECT \* FROM sessions WHERE  
> (session\_id = ‘875b6a6dff4de7e8bb2f7709cf9c31db’) LIMIT 1
