FIX: Can't boot Discourse with a read-only PG connection.

This commit is contained in:
Guo Xiang Tan 2018-06-11 12:29:23 +08:00
parent b91a3c12a5
commit 5656e8f366
2 changed files with 8 additions and 11 deletions

View File

@ -17,8 +17,10 @@ class PostgreSQLFallbackHandler
@initialized = false
MessageBus.subscribe(DATABASE_DOWN_CHANNEL) do |payload|
RailsMultisite::ConnectionManagement.with_connection(payload.data['db']) do
clear_connections
if @initialized
RailsMultisite::ConnectionManagement.with_connection(payload.data['db']) do
clear_connections
end
end
end
end
@ -28,14 +30,10 @@ class PostgreSQLFallbackHandler
@thread = Thread.new do
while true do
begin
thread = Thread.new { initiate_fallback_to_master }
thread.join
break if synchronize { @masters_down.hash.empty? }
sleep 10
ensure
thread.kill
end
thread = Thread.new { initiate_fallback_to_master }
thread.join
break if synchronize { @masters_down.hash.empty? }
sleep 10
end
end

View File

@ -27,7 +27,6 @@ describe ActiveRecord::ConnectionHandling do
let(:postgresql_fallback_handler) { PostgreSQLFallbackHandler.instance }
before do
skip("Figure out why this test leaks connections")
postgresql_fallback_handler.initialized = true
['default', multisite_db].each do |db|