Skip to content

Fix "A copy of ... has been removed from the module tree but is still active"

Mehmet Emin INAC requested to merge fix_missing_active_const_error into master

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;

  1. Set the reload_classes_only_on_change config value as false in development.rb.
  2. 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

Availability and Testing

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

Merge request reports