diff --git a/lib/sidekiq.rb b/lib/sidekiq.rb index 3ee4f9d26a..6f5d3c80f7 100644 --- a/lib/sidekiq.rb +++ b/lib/sidekiq.rb @@ -100,7 +100,8 @@ def self.redis # 2550 Failover can cause the server to become a replica, need # to disconnect and reopen the socket to get back to the primary. # 4495 Use the same logic if we have a "Not enough replicas" error from the primary - if retryable && ex.message =~ /READONLY|NOREPLICAS/ + # 4985 Use the same logic when a blocking command is force-unblocked + if retryable && ex.message =~ /READONLY|NOREPLICAS|master -> replica/ conn.disconnect! retryable = false retry diff --git a/test/test_sidekiq.rb b/test/test_sidekiq.rb index 7a1c625651..1852a6261b 100644 --- a/test/test_sidekiq.rb +++ b/test/test_sidekiq.rb @@ -96,6 +96,16 @@ assert_equal 2, counts.size assert_equal counts[0] + 1, counts[1] end + + it 'reconnects if instance state changed' do + counts = [] + Sidekiq.redis do |c| + counts << c.info['total_connections_received'].to_i + raise Redis::CommandError, "UNBLOCKED force unblock from blocking operation, instance state changed (master -> replica?)" if counts.size == 1 + end + assert_equal 2, counts.size + assert_equal counts[0] + 1, counts[1] + end end describe 'redis info' do