Skip to content

Address possible Memoization Bug in Gitlab::Database class

Summary

The Gitlab::Database class has two methods with different names but they share the same instance variable. These methods currently have the exact same implementation so this is is not yet an issue. But it could be an issue in the future.

Since the change is trivial, we can fix it easily

Steps to reproduce

In https://gitlab.com/gitlab-org/gitlab/-/blob/c8a06a8918b5e09f91526bfbac953da999042d87/lib/gitlab/database.rb#L86

  • Change the implementation of database_base_models_using_load_balancing method (for example, by removing 'ci') so it will return something different than database_base_models_with_gitlab_shared method
  • Open Rails console gdk rails c
    • Run Gitlab::Database.database_base_models_using_load_balancing
    • Run Gitlab::Database.database_base_models_with_gitlab_shared

What is the current bug behavior?

Expected return value of Gitlab::Database.database_base_models_with_gitlab_shared:

=> {"main"=>ActiveRecord::Base, "ci"=>Ci::ApplicationRecord(abstract)}

What is the expected correct behavior?

But it returns exactly the same as database_base_models_using_load_balancing

=> {"main"=>ActiveRecord::Base}