# 'Mysql has gone away'

**URL:** <https://www.ruby-forum.com/t/mysql-has-gone-away/49221>\
**Category:** Rails\
**Created:** [December 1, 2005, 4:13pm UTC](https://www.ruby-forum.com/t/mysql-has-gone-away/49221 "2005-12-01T16:13:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul.vudmaska](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/cdc98d/32.png) [@paul.vudmaska](https://www.ruby-forum.com/u/paul.vudmaska)\
**Post date:** [December 1, 2005, 4:13pm UTC](https://www.ruby-forum.com/t/mysql-has-gone-away/49221/1 "2005-12-01T16:13:13Z")

</div>

I’m using EdgeRails from SVN on TextDrive. I’m often getting ‘Mysql  
has gone away’ errors and my understanding is this is an issue with  
EdgeRails that is being addressed. Can anyone verify that for me?

I’m having some folks test things and I wanted to make sure my app was  
staying up, so in rescue\_action\_in\_public, I’m executing an .sh file  
that kills and restarts lighty. I can run this code on my local - but  
of course it is not happening here (i’m using lighty locally also -  
but I forced it to run in a controller and it restarted Lighty without  
problems)

Is that a dumb idea? Can you imagine any ill effects to others on TD?

Thanks to all!

:Paul

---

<div class="post-metadata">

**Author:** ![paul.vudmaska](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/cdc98d/32.png) [@paul.vudmaska](https://www.ruby-forum.com/u/paul.vudmaska)\
**Post date:** [December 1, 2005, 5:10pm UTC](https://www.ruby-forum.com/t/mysql-has-gone-away/49221/2 "2005-12-01T17:10:14Z")

</div>

You are correct. Here is a the ticket for this issue:

[http://dev.rubyonrails.org/ticket/428](http://dev.rubyonrails.org/ticket/428)

I am not sure about your proposal to restart lighty… someone said  
this could happen every 10 minutes. I have personally switched to the  
stable for now:

[http://dev.rubyonrails.org/svn/rails/branches/stable](http://dev.rubyonrails.org/svn/rails/branches/stable)

It was said that this issue is one of the last to be fixed before  
1.0… so hopefully it won’t be broken much longer.

Tom

---

<div class="post-metadata">

**Author:** ![paul.vudmaska](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/cdc98d/32.png) [@paul.vudmaska](https://www.ruby-forum.com/u/paul.vudmaska)\
**Post date:** [December 1, 2005, 7:12pm UTC](https://www.ruby-forum.com/t/mysql-has-gone-away/49221/3 "2005-12-01T19:12:01Z")

</div>

On 12/1/05, Paul V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m using EdgeRails from SVN on TextDrive. I’m often getting ‘Mysql  
> has gone away’ errors and my understanding is this is an issue with  
> EdgeRails that is being addressed. Can anyone verify that for me?

Thank god someone else is having the same problem as me! 🙂

---

<div class="post-metadata">

**Author:** ![paul.vudmaska](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/cdc98d/32.png) [@paul.vudmaska](https://www.ruby-forum.com/u/paul.vudmaska)\
**Post date:** [December 6, 2005, 8:28pm UTC](https://www.ruby-forum.com/t/mysql-has-gone-away/49221/4 "2005-12-06T20:28:52Z")

</div>

On 1-dec-2005, at 16:10, Paul V. wrote:

> Is that a dumb idea? Can you imagine any ill effects to others on TD?

Yes, it is - you are shooting birds with a cannon, so to speak.

If you want your app to be accessible, do SOME request in your  
prefilter and then catch it’s exception. If you get an exception with  
“MySQL has gone away” etc. it’s time to reconnect.

This is NOT clean and it shoulodn’t be done in this way butthe ticket  
has all the implications that you can read about.

begin  
ActiveRecord::Base.connection.execute “SET NAMES  
your\_favorite\_charset\_here”  
rescue ActiveRecord::StatementInvalid =\> e  
if e.to\_s =~ /away/  
ActiveRecord::Base.establish\_connection and retry  
else  
raise e  
end  
end

To be precise I would put another throw(:on\_reconnect) in there just  
to make sure this doesn’t happen indefinitely. I never noticed  
reconnection issues exactly because I’ve been using this since like  
May this year on all apps I develop.

–  
Julian ‘Julik’ Tarkhanov  
me at julik.nl
