Commit f908364d authored by Catalin Irimie's avatar Catalin Irimie

Fix DB connection check for Geo user routing

Overriding Geo routes should happen if the current node is a secondary.

However, simply checking `connected?` on the GeoNode model won't work
because Rails releases the DB connection before reloading routes
in the initializing phase, resulting in the GeoNode#connected? method
being an unreliable indicator for the DB connectivity.

Changelog: fixed
EE: true
parent 6f243cea
......@@ -44,7 +44,11 @@ module Gitlab
end
def self.connected?
GeoNode.connected? && GeoNode.table_exists?
# GeoNode#connected? only attempts to use existing DB connections so it can't
# be relied upon in initializers, without this active DB connectivity check.
active_db_connection = GeoNode.connection_pool.with_connection(&:active?) rescue false
active_db_connection && GeoNode.table_exists?
end
def self.enabled?
......
......@@ -165,8 +165,8 @@ RSpec.describe Gitlab::Geo, :geo, :request_store do
describe '.connected?' do
context 'when there is a database issue' do
it 'returns false when database connection is down' do
allow(GeoNode).to receive(:connected?) { false }
it 'returns false when it cannot open an active database connection' do
allow(GeoNode.connection).to receive(:active?).and_return(false)
expect(described_class.connected?).to be_falsey
end
......
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