Lost connection to MySQL server during query error with Rails3, octopus replication stone

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

It works pretty well.

I have one problem: the "Lost Communication" error occurs when a service is deployed using capistrano. Each deployment occurred approximately 3 times. The service uses the octopus axis from https://github.com/tchandy/octopus to replicate a database with 1 primary database and 2 subordinate databases.

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

The problem does not occur when the octopus is not used with the same database. But traffic requires replication.

Please give me some advice. Thanks.

+4
source share
2 answers

I am the creator of Octopus.

Can you add this to your shards.yml file?

 verify_connection: true 

Also, if this does not work, try setting up the rails to automatically reconnect:

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

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

+5
source

If you are using a Phusion Passenger and PassengerSpawnMethod smartphone.

 # 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 is using

 # database.yml and shards.yml reconnect: true 
+1
source

Source: https://habr.com/ru/post/1339529/


All Articles