Daemons causing Mysql::Error:Can't connect to local MySQL server through socket '/var/run/mysqld/my


#1

Hi all,

Ive been having this problem for the past few days on production. I
have a couple of daemons (using the daemons gem and daemon_generator)
that I run every hour on the server. One of them sends out email too
(just in case thats relevant information). Besides this, I have 4
Rails apps running on the server one of which contains the above
mentioned daemons.

Now everytime I deploy, I have a couple of Capistrano tasks that stop
the daemons before:update_code and start them again after:update_code.
This I do because they stop running altogether during the deployment
window because MySQL locks down and the daemons, when trying to
connect to MySQL, fail.

However, once both daemons are started, everything funcitons fine for
about 15-20 minutes after which, if I try to access any of the 4 Rails
apps, I get “Mysql::Error:Can’t connect to local MySQL server through
socket ‘/var/run/mysqld/mysqld.sock’”. I also sometimes get the “MySQL
server has gone away” error. I especially get the 2nd error in the
daemons logs when they try to run again.
Sometimes, when I try to access one of my apps, Passenger throws an
error saying

Passenger::Railz::ApplicationSpawner::Error
application_spawner.rb line 111 in `spawn_ application’

Now all these are related only to the daemons cos if I stop them and
reboot my server, the apps work just great.
Googling around, I found that the “MySQL server has gone away” error
can be fixed by adding

ActiveRecord::Base.connection.reconnect!

just before running AR queries from daemons. I tried it but it dint
stop the apps from crashing. Is the connection apparent to anyone? Any
ideas on how I can resolve this with least impact on my 4 apps running
on production??


#2

Ummm. Maybe I should cut the long story short.

couple of daemons, when running on server, slow down and crash my
Rails apps. Logs show me errors like

Mysql::Error:Can’t connect to local MySQL server through socket ‘/var/
run/mysqld/mysqld.sock’
&
MySQL server has gone away

Sometimes, I also get a Passenger::Railz::ApplicationSpawner::Error.
Any ideas on what might be going wrong? Tried
"ActiveRecord::Base.connection.reconnect! " in the daemons but that
dint help.