FWIW I did a hack in the mysql connection code to enable the
auto-reconnection property in the mysql driver - patch applied. Though
I never explicitly tested that it really did actually fix the issue
:). Not sure if there's a better approach though.
On 2/26/07, Andrew Kuklewicz <kooks...@gmail.com> wrote:
> Hey folks,
> After long periods of inactivity (>~8 hours) that my a13g based app
> often has overnight on weekends, I am noticing db timout errors from
> mysql of the "Mysql::Error: MySQL server has gone away" variety.
> Looking around a bit, I got a clue from the mogrel docs to solve this
> using:
> ActiveRecord::Base.verification_timeout = 14400
> But this timeout value is really only used by the
> 'ActiveRecord::Base.verify_active_connections!', which gets called in
> rails from the following sequence:
> Dispatcher::dispatch -> prepare_application ->
> ActiveRecord::Base.verify_active_connections!
> So setting verification_timeout value does nothing on its own, and
> since the poller in a13g does not call the verify_active_connections!,
> setting this value would do nothing.
> So my proposed solution (I am testing this now) is to add the
> verify_active_connections call to the
> ActiveMessaging::Gateway.dispatch method to do the same thing Rails
> does - make sure this connection is good before sending it off to be
> processed.
> Anyone else seeing this problem, or have a better idea for a solution?
> - Andrew
--
James
-------
http://radio.weblogs.com/0112098/
[
patch.txt ]
Index: activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
===================================================================
--- activerecord/lib/active_record/connection_adapters/mysql_adapter.rb (revision 5909)
+++ activerecord/lib/active_record/connection_adapters/mysql_adapter.rb (working copy)
@@ -79,6 +79,12 @@
mysql = Mysql.init
mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslkey]
+ # lets default the auto reconnect option to true unless its specified in the configuration
+ # as it seems many people hit the mysql connections being timed out issue
+ value = config[:reconnect]
+ value = true if value.nil?
+ mysql.reconnect = value
+
ConnectionAdapters::MysqlAdapter.new(mysql, logger, [host, username, password, database, port, socket], config)
end
end