From f504e7968d0088ce1d031b2ed9a8717271f6b770 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 12 Jun 2024 19:31:50 +0200 Subject: [PATCH] chore(redis): reduce connect timeout from 1s to 0.2s Prevent web workers from being stalled when Redis is down. --- config/environments/production.rb | 18 +++++++++++------- config/initializers/kredis.rb | 3 ++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 64ed28732..5008e6071 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -62,17 +62,21 @@ Rails.application.configure do # Use a different cache store in production. if ENV['REDIS_CACHE_URL'].present? - redis_options = { url: ENV['REDIS_CACHE_URL'] } - redis_options[:ssl] = (ENV['REDIS_CACHE_SSL'] == 'enabled') + redis_options = { + url: ENV['REDIS_CACHE_URL'], + connect_timeout: 0.2, + error_handler: -> (method:, returning:, exception:) { + Sentry.capture_exception exception, level: 'warning', + tags: { method: method, returning: returning } + } + } + + redis_options[:ssl] = ENV['REDIS_CACHE_SSL'] == 'enabled' + if ENV['REDIS_CACHE_SSL_VERIFY_NONE'] == 'enabled' redis_options[:ssl_params] = { verify_mode: OpenSSL::SSL::VERIFY_NONE } end - redis_options[:error_handler] = -> (method:, returning:, exception:) { - Sentry.capture_exception exception, level: 'warning', - tags: { method: method, returning: returning } - } - config.cache_store = :redis_cache_store, redis_options end diff --git a/config/initializers/kredis.rb b/config/initializers/kredis.rb index 878b8177a..90dd906b9 100644 --- a/config/initializers/kredis.rb +++ b/config/initializers/kredis.rb @@ -1,6 +1,7 @@ redis_volatile_options = { url: ENV['REDIS_CACHE_URL'], # will fallback to default redis url if empty, and won't fail if there is no redis server - ssl: ENV['REDIS_CACHE_SSL'] == 'enabled' + ssl: ENV['REDIS_CACHE_SSL'] == 'enabled', + connect_timeout: 0.2 } redis_volatile_options[:ssl_params] = { verify_mode: OpenSSL::SSL::VERIFY_NONE } if ENV['REDIS_CACHE_SSL_VERIFY_NONE'] == 'enabled'