Skip to content
Snippets Groups Projects
Commit a2a5af3a authored by Kamil Trzcińśki's avatar Kamil Trzcińśki
Browse files

Fix handling for `GitlabSchemasValidateConnection` for early start

It appears that each connection needs to be adopted. However,
in it's initial phase (before being adopted) the Rails
might execute SQL queries to configure the connection settings
(collation, timeouts, etc.). This will happen before
the connection is actually assigned to the connection pool,
as if such connection will be failed to be initialized
it will be orphaned.
parent fb022a8a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -203,8 +203,13 @@ def self.db_config_names
# This does not look at literal connection names, but rather compares
# models that are holders for a given db_config_name
def self.gitlab_schemas_for_connection(connection)
db_name = self.db_config_name(connection)
primary_model = self.database_base_models.fetch(db_name.to_sym)
db_config = self.db_config_for_connection(connection)
# connection might not be yet adopted (returning NullPool, and no connection_klass)
# in such cases it is fine to ignore such connections
return unless db_config
primary_model = self.database_base_models.fetch(db_config.name.to_sym)
 
self.schemas_to_base_models.select do |_, child_models|
child_models.any? do |child_model|
Loading
Loading
Loading
Loading
@@ -222,10 +222,6 @@
end
 
describe '.gitlab_schemas_for_connection' do
it 'does raise exception for invalid connection' do
expect { described_class.gitlab_schemas_for_connection(:invalid) }.to raise_error /key not found: "unknown"/
end
it 'does return a valid schema depending on a base model used', :request_store do
# FF due to lib/gitlab/database/load_balancing/configuration.rb:92
stub_feature_flags(force_no_sharing_primary_model: true)
Loading
Loading
@@ -282,6 +278,15 @@
end
end
end
it 'does return empty for non-adopted connections' do
new_connection = ActiveRecord::Base.postgresql_connection(
ActiveRecord::Base.connection_db_config.configuration_hash)
expect(described_class.gitlab_schemas_for_connection(new_connection)).to be_nil
ensure
new_connection&.disconnect!
end
end
 
describe '#true_value' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment