Fix "A copy of ... has been removed from the module tree but is still active"
What does this MR do?
When we refer to a constant from initializers which is supposed to be loaded by ActiveSupport::Dependencies
, it's possible to get an error in the development environment if Rails tries to load/reload a missing constant under the namespace of that constant.
The reason is since the constant is loaded in initializers, it stays in the memory and conflicts with the one reloaded by Rails.
This commit fixes only the Gitlab::Metrics::Subscribers::ActiveRecord
case which has been used in lograge configuration. There are probably more of these cases and we should stop using constants located under the autoload paths in our initializers or fix the errors by following the same approach with this MR if there is no other way to use other than the constants defined under the autoload paths.
How to reproduce this error
This error happens from time to time when there is a change that triggers the process to reload the constants but there is also a way to make the error consistent by changing the Rails & Puma configurations;
- Set the
reload_classes_only_on_change
config value as false indevelopment.rb
. - Decrease the workers count of Puma to 1 in
puma.rb
(workers 1
).
With these configuration changes, you can reproduce the error.
Screenshots
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry
- [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Availability and Testing
- [-] Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process.
- [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- [-] Label as security and @ mention
@gitlab-com/gl-security/appsec
- [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
- [-] Security reports checked/validated by a reviewer from the AppSec team