From 6fe2f874258eb589d3ccdc8111b4e7f904c3e6a8 Mon Sep 17 00:00:00 2001 From: Kevin Dew Date: Thu, 23 Jan 2025 11:49:32 +0000 Subject: [PATCH] Reduce the time window for Sidekiq retries The previous code meant that if there was a Sidekiq connection error there would be a `sleep(15)` called before any attempt to reconnect to Redis. For a client application serving a web request and adding to the Sidekiq this 15 seconds is a very long time to wait. This is substantially longer than the gem default values which are a 0.25s wait twice [1] The motivation for making this change was finding that in a Heroku environment (which we are currently using for demoing an app) it is frequent that we receive an intermittment 15 second wait to serve a request. The Redis connection must be less reliable on the cheaper hardware. [1]: https://github.com/redis-rb/redis-client/blob/8dfe1f65208482bb30150dd0009254ac77fe4776/lib/redis_client/sentinel_config.rb#L7-L8 --- CHANGELOG.md | 3 +++ lib/govuk_sidekiq/sidekiq_initializer.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d394de5..93e5333 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog + +* Reduce Redis reconnection timeout from 15-60s to 0.05-5s + ## 9.0.3 * Update dependencies diff --git a/lib/govuk_sidekiq/sidekiq_initializer.rb b/lib/govuk_sidekiq/sidekiq_initializer.rb index 3abe0f5..5661a1b 100644 --- a/lib/govuk_sidekiq/sidekiq_initializer.rb +++ b/lib/govuk_sidekiq/sidekiq_initializer.rb @@ -5,7 +5,7 @@ module GovukSidekiq module SidekiqInitializer def self.setup_sidekiq(redis_config = {}) - redis_config = redis_config.merge(reconnect_attempts: [15, 30, 45, 60]) + redis_config = redis_config.merge(reconnect_attempts: [0.05, 0.25, 1, 5]) Sidekiq.configure_server do |config| # $real_stdout is defined by govuk_app_config and is used to point to