Possible load ordering problem with Gitlab::LoadBalancing
Symptom
Since !68042 (merged), the database testing tool used to test migrations started failing consistently
It turns out that the database testing tool patches out config/initializers/asset_proxy_settings.rb
to comment out :
$ git diff
diff --git a/config/initializers/asset_proxy_settings.rb b/config/initializers/asset_proxy_settings.rb
index 48eedcee681f..233391ac29cf 100644
--- a/config/initializers/asset_proxy_settings.rb
+++ b/config/initializers/asset_proxy_settings.rb
@@ -4,5 +4,5 @@
# Asset proxy settings
#
ActiveSupport.on_load(:active_record) do
- Banzai::Filter::AssetProxyFilter.initialize_settings
+ #Banzai::Filter::AssetProxyFilter.initialize_settings
end
Problem
For some reason because Banzai::Filter::AssetProxyFilter.initialize_settings
calls, and loads ApplicationSettings, we avoid the error from that issue.
Reproduction
-
Apply the diff above
-
Run any rake task that depends on
:environment
such as:RAILS_ENV=test bin/rake gettext:regenerate
-
Observe error, and
already initialized constant
warnings
$ bin/rake gettext:regenerate
/Users/tkuah/code/ee-gdk/gitlab/app/models/application_setting.rb:14: warning: already initialized constant ApplicationSetting::INSTANCE_REVIEW_MIN_USERS
/Users/tkuah/code/ee-gdk/gitlab/app/models/application_setting.rb:14: warning: previous definition of INSTANCE_REVIEW_MIN_USERS was here
/Users/tkuah/code/ee-gdk/gitlab/app/models/application_setting.rb:15: warning: already initialized constant ApplicationSetting::GRAFANA_URL_ERROR_MESSAGE
/Users/tkuah/code/ee-gdk/gitlab/app/models/application_setting.rb:15: warning: previous definition of GRAFANA_URL_ERROR_MESSAGE was here
/Users/tkuah/code/ee-gdk/gitlab/app/models/application_setting.rb:18: warning: already initialized constant ApplicationSetting::KROKI_URL_ERROR_MESSAGE
/Users/tkuah/code/ee-gdk/gitlab/app/models/application_setting.rb:18: warning: previous definition of KROKI_URL_ERROR_MESSAGE was here
rake aborted!
ArgumentError: You tried to define an enum named "whats_new_variant" on the model "ApplicationSetting", but this will generate a instance method "whats_new_variant_all_tiers?", which is already defined by another enum.
/Users/tkuah/code/ee-gdk/gitlab/app/models/application_setting.rb:21:in `<class:ApplicationSetting>'
/Users/tkuah/code/ee-gdk/gitlab/app/models/application_setting.rb:3:in `<main>'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/current_settings.rb:76:in `fake_application_settings'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/current_settings.rb:58:in `uncached_application_settings'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/current_settings.rb:42:in `ensure_application_settings!'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/current_settings.rb:15:in `block in current_application_settings'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/null_request_store.rb:34:in `fetch'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/safe_request_store.rb:12:in `fetch'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/current_settings.rb:15:in `current_application_settings'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/current_settings.rb:32:in `method_missing'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/metrics/prometheus.rb:98:in `prometheus_metrics_enabled_unmemoized'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/metrics/prometheus.rb:24:in `block in prometheus_metrics_enabled?'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/utils/strong_memoize.rb:30:in `strong_memoize'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/metrics/prometheus.rb:23:in `prometheus_metrics_enabled?'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/metrics/prometheus.rb:90:in `provide_metric'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/metrics/prometheus.rb:81:in `safe_provide_metric'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/metrics/prometheus.rb:55:in `gauge'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/database/load_balancing/host_list.rb:13:in `initialize'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:27:in `new'
/Users/tkuah/code/ee-gdk/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:27:in `initialize'
/Users/tkuah/code/ee-gdk/gitlab/config/initializers/load_balancing.rb:24:in `new'
/Users/tkuah/code/ee-gdk/gitlab/config/initializers/load_balancing.rb:24:in `block in <main>'
/Users/tkuah/code/ee-gdk/gitlab/config/initializers/load_balancing.rb:36:in `<main>'
/Users/tkuah/code/ee-gdk/gitlab/config/environment.rb:7:in `<main>'
/Users/tkuah/code/ee-gdk/gitlab/lib/tasks/gettext.rake:37:in `block (2 levels) in <main>'
Tasks: TOP => gettext:find => gettext:setup => environment
(See full trace by running task with --trace)
Impact
Note: It is unlikely we will ever remove that Banzai line so this might never be a real problem, also this only happens in test env.
Edited by Thong Kuah