diff --git a/config/initializers/7_redis.rb b/config/initializers/7_redis.rb index fbd2cbaabad64847720c12be3f8ea4cdea434876..72f5574334d7d9afaee4bd5216b2755d7e07c4d9 100644 --- a/config/initializers/7_redis.rb +++ b/config/initializers/7_redis.rb @@ -30,6 +30,7 @@ # this only instruments `RedisClient` used in `Sidekiq.redis` RedisClient.register(Gitlab::Instrumentation::RedisClientMiddleware) RedisClient.prepend(Gitlab::Patch::RedisClient) +RedisClient::SentinelConfig.prepend(Gitlab::Patch::RedisClientSentinelConfig) if Gitlab::Redis::Workhorse.params[:cluster].present? raise "Do not configure workhorse with a Redis Cluster as pub/sub commands are not cluster-compatible." diff --git a/lib/gitlab/patch/redis_client_sentinel_config.rb b/lib/gitlab/patch/redis_client_sentinel_config.rb new file mode 100644 index 0000000000000000000000000000000000000000..f1a6a02214e4a44cb95c19071b9ff8ac7923fd7e --- /dev/null +++ b/lib/gitlab/patch/redis_client_sentinel_config.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +if Gem::Version.new(RedisClient::VERSION) != Gem::Version.new('0.20.0') + raise 'New version of redis-client detected, please remove or update this patch' +end + +module Gitlab + module Patch + module RedisClientSentinelConfig + # we manually apply the fix in + # https://github.com/redis-rb/redis-client/commit/26d355441f5b455294de887397ed8bea2e2c7275 + # until a new tag is released + def each_sentinel + last_error = nil + # rubocop:disable Gitlab/ModuleWithInstanceVariables -- Directly references code in redis-client gem + @sentinel_configs.dup.each do |sentinel_config| + sentinel_client = sentinel_client(sentinel_config) + success = true + begin + yield sentinel_client + rescue RedisClient::Error => error + last_error = error + success = false + sleep SENTINEL_DELAY + ensure + @sentinel_configs.unshift(@sentinel_configs.delete(sentinel_config)) if success + # Redis Sentinels may be configured to have a lower maxclients setting than + # the Redis nodes. Close the connection to the Sentinel node to avoid using + # a connection. + sentinel_client.close + # rubocop:enable Gitlab/ModuleWithInstanceVariables + end + end + end + end + end +end