From 581cfbae24d629433e2e4eb6f6a2bb2a2938cada Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 13 Feb 2017 17:11:50 +0100 Subject: [PATCH] Don't connect in Gitlab::Database.adapter_name We don't need to connect when requesting the name of the database adapter. This in turn should prevent us from requesting/leaking connections just by asking whether we're using PostgreSQL or MySQL. --- changelogs/unreleased/fix-ar-connection-leaks.yml | 4 ++++ lib/gitlab/database.rb | 2 +- spec/lib/gitlab/database_spec.rb | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/fix-ar-connection-leaks.yml diff --git a/changelogs/unreleased/fix-ar-connection-leaks.yml b/changelogs/unreleased/fix-ar-connection-leaks.yml new file mode 100644 index 00000000000..9da715560ad --- /dev/null +++ b/changelogs/unreleased/fix-ar-connection-leaks.yml @@ -0,0 +1,4 @@ +--- +title: Don't connect in Gitlab::Database.adapter_name +merge_request: +author: diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index dc2537d36aa..a3d6be9959b 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -6,7 +6,7 @@ module Gitlab MAX_INT_VALUE = 2147483647 def self.adapter_name - connection.adapter_name + ActiveRecord::Base.configurations[Rails.env]['adapter'] end def self.mysql? diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb index b142b3a2781..41252f31997 100644 --- a/spec/lib/gitlab/database_spec.rb +++ b/spec/lib/gitlab/database_spec.rb @@ -5,6 +5,12 @@ class MigrationTest end describe Gitlab::Database, lib: true do + describe '.adapter_name' do + it 'returns the name of the adapter' do + expect(described_class.adapter_name).to be_an_instance_of(String) + end + end + # These are just simple smoke tests to check if the methods work (regardless # of what they may return). describe '.mysql?' do