R
R
Rustam2011-02-18 19:21:43
ruby
Rustam, 2011-02-18 19:21:43

ruby-mysql2: MySQL server has gone away

There is a daemon written in ruby ​​using the mysql2 gem, which sometimes receives a message from AMQP and writes to the database.

When idle for a long time, MySQL closes the connection by timeout and when you try to execute the query, the exception 'MySQL server has gone away' is thrown. Google issues a solution for ActiveRecord, nothing about mysql2. I did not find anything suitable in the methods of the Mysql2::Client class, the :reconnect => true option does not help.

How to check the connection before executing the request and if it is closed, then raise it again?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
eternals, 2011-02-18
@eternals

I don't know shit, but in mysql connectors you can usually check with the Ping function.

R
Riateche, 2011-02-18
@Riateche

Catch the exception and do Client.new again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question