Skip to content

Commit

Permalink
fix: change the behavior of subscription in pubsub when the node is u…
Browse files Browse the repository at this point in the history
…nstable
  • Loading branch information
supercaracal committed Oct 13, 2024
1 parent b9b3b71 commit 1517ef8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/redis_client/cluster/pub_sub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ def spawn_worker(client, queue)
# It is a fixed size but we can modify the size with some environment variables.
# So it consumes memory 1 MB multiplied a number of workers.
Thread.new(client, queue) do |pubsub, q|
prev_err = nil

loop do
q << pubsub.next_event
prev_err = nil
rescue StandardError => e
q << e
if e.instance_of?(prev_err.class) && e.message == prev_err&.message
sleep 0.005
else
q << e
prev_err = e
end
end
end
end
Expand Down Expand Up @@ -160,7 +168,6 @@ def start_over
@router.renew_cluster_state
@state_dict.each_value(&:close)
@state_dict.clear
@queue.clear
@commands.each { |command| _call(command) }
break
rescue ::RedisClient::ConnectionError, ::RedisClient::Cluster::NodeMightBeDown
Expand Down

0 comments on commit 1517ef8

Please sign in to comment.