Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dalli::Client doesn't pick up the value of MEMCACHE_SERVERS when used with Rails #44642

Closed
radiantshaw opened this issue Mar 9, 2022 · 1 comment

Comments

@radiantshaw
Copy link

Steps to reproduce

  • Create a new Rails app
  • Set config.cache_store to :mem_cache_store
  • Install the dalli gem
  • Set the value of MEMCACHE_SERVERS env variable
  • Access the Memcache server via an instance of Dalli::Client
  • Now do the same with the object provided by Rails.cache
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  # Activate the gem you are reporting the issue against.
  gem "activesupport", "~> 6.0.4.6"
  gem "dalli", "~> 2.7.6"
end

require "active_support"
require "active_support/core_ext/object/blank"
require "minitest/autorun"

class MemCacheBugTest < Minitest::Test
  def test_dalli_client_reads_memcache_servers_env_var
    ENV.stub :[], "memcached.example.com:11211" do
      dalli_client = Dalli::Client.new
      assert_includes dalli_client.instance_variable_get(:@servers), "memcached.example.com:11211"
    end
  end

  def test_rails_cache_does_not_read_memcache_servers_env_var
    ENV.stub :[], "memcached.example.com:11211" do
      dalli_client = ActiveSupport::Cache::MemCacheStore.new.instance_variable_get(:@data)
      refute_includes dalli_client.instance_variable_get(:@servers), "memcached.example.com:11211"
    end
  end
end

Expected behavior

Rails configuration shouldn't prevent Dalli::Client instances from reading the value of MEMCACHE_SERVERS env variable.

Actual behavior

Rails configuration prevents Dalli::Client instances from reading the value of MEMCACHE_SERVERS env variable.

System configuration

Rails version: 6.0.4.6

Ruby version: 2.7.5

@fatkodima
Copy link
Member

It was fixed in rails 6.1.0 - #40420, you need to upgrade.

@matthewd matthewd closed this as completed Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants