A platform for community discussion. Free, open, simple.
Be more forceful in disconnecting connections during failover.
Guo Xiang Tan08b268c5bcb6
diff --git a/lib/active_record/connection_adapters/postgresql_fallback_adapter.rb b/lib/active_record/connection_adapters/postgresql_fallback_adapter.rbindex 812f8d2168c..6016b162c08 100644--- a/lib/active_record/connection_adapters/postgresql_fallback_adapter.rb+++ b/lib/active_record/connection_adapters/postgresql_fallback_adapter.rb@@ -99,7 +99,7 @@ class PostgreSQLFallbackHandlerenddef clear_connections- ActiveRecord::Base.connection_pool.disconnect+ ActiveRecord::Base.connection_pool.disconnect!endprivatediff --git a/spec/components/active_record/connection_adapters/postgresql_fallback_adapter_spec.rb b/spec/components/active_record/connection_adapters/postgresql_fallback_adapter_spec.rbindex c207a6ba141..2d8bdc6cfeb 100644--- a/spec/components/active_record/connection_adapters/postgresql_fallback_adapter_spec.rb+++ b/spec/components/active_record/connection_adapters/postgresql_fallback_adapter_spec.rb@@ -38,22 +38,18 @@ describe ActiveRecord::ConnectionHandling doafter doSidekiq.unpause!postgresql_fallback_handler.setup!- Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)ActiveRecord::Base.unstub(:postgresql_connection)(Thread.list - @threads).each(&:kill)+ ActiveRecord::Base.connection_pool.disconnect!ActiveRecord::Base.establish_connectionenddescribe "#postgresql_fallback_connection" doit 'should return a PostgreSQL adapter' do- begin- connection = ActiveRecord::Base.postgresql_fallback_connection(config)+ connection = ActiveRecord::Base.postgresql_fallback_connection(config)- expect(connection)- .to be_an_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)- ensure- connection.disconnect!- end+ expect(connection)+ .to be_an_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)endcontext 'when master server is down' do@@ -127,8 +123,6 @@ describe ActiveRecord::ConnectionHandling doexpect(Discourse.readonly_mode?).to eq(false)expect(Sidekiq.paused?).to eq(false)-- # fails sometimes on this line!expect(ActiveRecord::Base.connection_pool.connections.count).to eq(0)expect(postgresql_fallback_handler.master_down?).to eq(nil)