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

Reconnect on "UNBLOCKED force unblock" errors #4985

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|UNBLOCKED/
conn.disconnect!
retryable = false
retry
Expand Down
10 changes: 10 additions & 0 deletions test/test_sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down