mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Don't clear connections on the same process.
This commit is contained in:
@@ -16,8 +16,8 @@ class PostgreSQLFallbackHandler
|
|||||||
@mutex = Mutex.new
|
@mutex = Mutex.new
|
||||||
@initialized = false
|
@initialized = false
|
||||||
|
|
||||||
MessageBus.subscribe(DATABASE_DOWN_CHANNEL) do |payload|
|
MessageBus.subscribe(DATABASE_DOWN_CHANNEL) do |payload, pid|
|
||||||
if @initialized
|
if @initialized && pid != Process.pid
|
||||||
RailsMultisite::ConnectionManagement.with_connection(payload.data['db']) do
|
RailsMultisite::ConnectionManagement.with_connection(payload.data['db']) do
|
||||||
clear_connections
|
clear_connections
|
||||||
end
|
end
|
||||||
@@ -49,7 +49,7 @@ class PostgreSQLFallbackHandler
|
|||||||
synchronize do
|
synchronize do
|
||||||
@masters_down[namespace] = true
|
@masters_down[namespace] = true
|
||||||
Sidekiq.pause! if !Sidekiq.paused?
|
Sidekiq.pause! if !Sidekiq.paused?
|
||||||
MessageBus.publish(DATABASE_DOWN_CHANNEL, db: namespace)
|
MessageBus.publish(DATABASE_DOWN_CHANNEL, db: namespace, pid: Process.pid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ describe ActiveRecord::ConnectionHandling do
|
|||||||
after do
|
after do
|
||||||
postgresql_fallback_handler.setup!
|
postgresql_fallback_handler.setup!
|
||||||
Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
|
Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
|
||||||
|
ActiveRecord::Base.unstub(:postgresql_connection)
|
||||||
|
ActiveRecord::Base.establish_connection
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#postgresql_fallback_connection" do
|
describe "#postgresql_fallback_connection" do
|
||||||
@@ -53,7 +55,6 @@ describe ActiveRecord::ConnectionHandling do
|
|||||||
|
|
||||||
context 'when master server is down' do
|
context 'when master server is down' do
|
||||||
before do
|
before do
|
||||||
|
|
||||||
@replica_connection = mock('replica_connection')
|
@replica_connection = mock('replica_connection')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user