FIX: Don't clear connections on the same process.

This commit is contained in:
Guo Xiang Tan 2018-06-12 13:03:55 +08:00
parent 003df147a5
commit 7c173265d5
2 changed files with 5 additions and 4 deletions

View File

@ -16,8 +16,8 @@ class PostgreSQLFallbackHandler
@mutex = Mutex.new
@initialized = false
MessageBus.subscribe(DATABASE_DOWN_CHANNEL) do |payload|
if @initialized
MessageBus.subscribe(DATABASE_DOWN_CHANNEL) do |payload, pid|
if @initialized && pid != Process.pid
RailsMultisite::ConnectionManagement.with_connection(payload.data['db']) do
clear_connections
end
@ -49,7 +49,7 @@ class PostgreSQLFallbackHandler
synchronize do
@masters_down[namespace] = true
Sidekiq.pause! if !Sidekiq.paused?
MessageBus.publish(DATABASE_DOWN_CHANNEL, db: namespace)
MessageBus.publish(DATABASE_DOWN_CHANNEL, db: namespace, pid: Process.pid)
end
end

View File

@ -37,6 +37,8 @@ describe ActiveRecord::ConnectionHandling do
after do
postgresql_fallback_handler.setup!
Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
ActiveRecord::Base.unstub(:postgresql_connection)
ActiveRecord::Base.establish_connection
end
describe "#postgresql_fallback_connection" do
@ -53,7 +55,6 @@ describe ActiveRecord::ConnectionHandling do
context 'when master server is down' do
before do
@replica_connection = mock('replica_connection')
end