Commit 71f94914 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix-incident-5349' into 'master'

Duing application init connection can be assigned to `NullPool`

See merge request gitlab-org/gitlab!68154
parents 49489be2 04180eaf
...@@ -133,6 +133,11 @@ module Gitlab ...@@ -133,6 +133,11 @@ module Gitlab
# as this is dependent on a execution context # as this is dependent on a execution context
return ROLE_UNKNOWN if connection.is_a?(ConnectionProxy) return ROLE_UNKNOWN if connection.is_a?(ConnectionProxy)
# During application init we might receive `NullPool`
return ROLE_UNKNOWN unless connection.respond_to?(:pool) &&
connection.pool.respond_to?(:db_config) &&
connection.pool.db_config.respond_to?(:name)
if connection.pool.db_config.name.ends_with?(LoadBalancer::REPLICA_SUFFIX) if connection.pool.db_config.name.ends_with?(LoadBalancer::REPLICA_SUFFIX)
ROLE_REPLICA ROLE_REPLICA
else else
......
...@@ -304,6 +304,15 @@ RSpec.describe Gitlab::Database::LoadBalancing do ...@@ -304,6 +304,15 @@ RSpec.describe Gitlab::Database::LoadBalancing do
end end
end end
context 'when the NullPool is used for connection' do
let(:pool) { ActiveRecord::ConnectionAdapters::NullPool.new }
let(:connection) { double(:connection, pool: pool) }
it 'returns unknown' do
expect(described_class.db_role_for_connection(connection)).to eq(:unknown)
end
end
context 'when the load balancing is configured' do context 'when the load balancing is configured' do
let(:db_host) { ActiveRecord::Base.connection_pool.db_config.host } let(:db_host) { ActiveRecord::Base.connection_pool.db_config.host }
let(:proxy) { described_class::ConnectionProxy.new([db_host]) } let(:proxy) { described_class::ConnectionProxy.new([db_host]) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment