# Rails 2.2.2 - Mysql::Error: MySQL server has gone away

**URL:** <https://www.ruby-forum.com/t/rails-2-2-2-mysql-mysql-server-has-gone-away/161854>\
**Category:** Rails\
**Created:** [March 3, 2009, 3:56am UTC](https://www.ruby-forum.com/t/rails-2-2-2-mysql-mysql-server-has-gone-away/161854 "2009-03-03T03:56:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![a2ahmad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@a2ahmad](https://www.ruby-forum.com/u/a2ahmad)\
**Post date:** [March 3, 2009, 3:56am UTC](https://www.ruby-forum.com/t/rails-2-2-2-mysql-mysql-server-has-gone-away/161854/1 "2009-03-03T03:56:28Z")

</div>

My app consists of receiving emails with image attachments from its  
users so I have been employing the MMS2R gem and Fetcher. Every 60  
seconds the app goes to the email server to fetch emails.

Under Rails 2.1.1 things worked fine - when I received an email, the  
email was fetched, parsed and saved to the database.

However I needed to upgrade to Rails 2.2.2 for unrelated reasons and now  
I get the following error in my log when the app tries to save to the  
database. Emailpic is just the model in the database.

"Emailpic Columns (0.0ms) Mysql::Error: MySQL server has gone away:  
SHOW FIELDS FROM `emailpics`"

Does anyone know what changed between 2.1.1 and 2.2.2 to cause this to  
happen?

---

<div class="post-metadata">

**Author:** ![a2ahmad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@a2ahmad](https://www.ruby-forum.com/u/a2ahmad)\
**Post date:** [March 3, 2009, 5:32am UTC](https://www.ruby-forum.com/t/rails-2-2-2-mysql-mysql-server-has-gone-away/161854/2 "2009-03-03T05:32:23Z")

</div>

This was solved by the fine guys at Engine Y…  
I added the following lines to my environmemnt.rb:

ActiveRecord::Base.allow\_concurrency = true  
ActiveRecord::Base.verification\_timeout = 10

And just before I do a fetch I have this line:

Emailpic.verify\_active\_connections!

---

<div class="post-metadata">

**Author:** ![a2ahmad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@a2ahmad](https://www.ruby-forum.com/u/a2ahmad)\
**Post date:** [March 9, 2009, 5:57am UTC](https://www.ruby-forum.com/t/rails-2-2-2-mysql-mysql-server-has-gone-away/161854/3 "2009-03-09T05:57:30Z")

</div>

Adeel,

This worked for you with activerecord 2.2.2 ?

The Engineyard guys suggested the same thing to me, but we’re getting  
this deprecation working…

DEPRECATION WARNING: ActiveRecord::Base.verification\_timeout= has been  
deprecated and no longer has any effect. Please remove all references to  
verification\_timeout=… (called from verification\_timeout= at  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_specification.rb:106)

Tung

Adeel A. wrote:

> This was solved by the fine guys at Engine Y…  
> I added the following lines to my environmemnt.rb:
> 
> ActiveRecord::Base.allow\_concurrency = true  
> ActiveRecord::Base.verification\_timeout = 10
> 
> And just before I do a fetch I have this line:
> 
> Emailpic.verify\_active\_connections!

---

<div class="post-metadata">

**Author:** ![a2ahmad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@a2ahmad](https://www.ruby-forum.com/u/a2ahmad)\
**Post date:** [March 9, 2009, 6:25am UTC](https://www.ruby-forum.com/t/rails-2-2-2-mysql-mysql-server-has-gone-away/161854/4 "2009-03-09T06:25:17Z")

</div>

I just wonder if there’s a more automated way of doing this, instead of  
manually have to check the connection every time we do a mysql query…

---

<div class="post-metadata">

**Author:** ![a2ahmad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@a2ahmad](https://www.ruby-forum.com/u/a2ahmad)\
**Post date:** [March 9, 2009, 6:24am UTC](https://www.ruby-forum.com/t/rails-2-2-2-mysql-mysql-server-has-gone-away/161854/5 "2009-03-09T06:24:24Z")

</div>

ic, youre doing a

Emailpic.verify\_active\_connections!

So, thats what is probably reestablishing the connection…

---

<div class="post-metadata">

**Author:** ![a2ahmad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@a2ahmad](https://www.ruby-forum.com/u/a2ahmad)\
**Post date:** [March 21, 2009, 10:21pm UTC](https://www.ruby-forum.com/t/rails-2-2-2-mysql-mysql-server-has-gone-away/161854/6 "2009-03-21T22:21:53Z")

</div>

I’m getting these MySQL server has gone away on SHOW FIELDS too. I’ve  
spent a fair bit of effort trying to figure out what’s going on, with  
no success. All we’ve determined is it seems to have a higher chance  
of happening after some idle time. I can usually make it happen by  
hitting an ajax page with many requests at once (just spamming the  
ajax). Any ideas welcome.

On Mar 2, 10:56 pm, Adeel A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![a2ahmad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@a2ahmad](https://www.ruby-forum.com/u/a2ahmad)\
**Post date:** [March 26, 2009, 2:32am UTC](https://www.ruby-forum.com/t/rails-2-2-2-mysql-mysql-server-has-gone-away/161854/7 "2009-03-26T02:32:52Z")

</div>

I’ve had some success with the mysql\_retry\_lost\_connection gem.
