4
votes

I just upgrade my web service from Rails 2.3.8 to Rails 3.0.3

It's almost working well.

I has one problem, Lost connection error is occurred when the service is deployed with capistrano. About 3 times occurred every deployment. The service use octopus gem from https://github.com/tchandy/octopus for database replication with 1 master database and 2 slave database.

Mysql::Error: Lost connection to MySQL server during query: SELECT regions.* FROM regions WH ...

The problem is not occurred when octopus is not used with single database. But replication is needed for traffic.

Please, give me any advise. Thank you.

2

2 Answers

5
votes

I'm the creator of Octopus.

Can you add this to your shards.yml file?

verify_connection: true

Also, if that don't work, try to configure rails to automatic reconnect:

http://guides.rubyonrails.org/2_3_release_notes.html#reconnecting-mysql-connections

Obs: this will work only with mysql adapter, not mysql2.

1
votes

If your using Phusion Passenger and PassengerSpawnMethod smart.

# config/initializers/phusion_passenger.rb
if defined?(PhusionPassenger)
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
    if forked
      # the following is *required* for Rails + "PassengerSpawnMethod smart".
      if defined?(ActiveRecord::Base)
        # force reconnect to "master" connection.
        ActiveRecord::Base.connection_pool.disconnect!

        # force reconnect to our octopus "slave" pools. This may include the "master" pool above.
        if defined?(Octopus)
          ActiveRecord::Base.connection_proxy.instance_variable_get(:@shards).each { |name, pool| pool.disconnect! }
        end
      end
    end
  end
end

This with:

# database.yml and shards.yml
reconnect: true