Skip to content

Commit

Permalink
fix: the behavior of subscription in pubsub when nodes are unstable (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
supercaracal authored Oct 13, 2024
1 parent b9b3b71 commit 6f40d8b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/redis_client/cluster/pub_sub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ def spawn_worker(client, queue)
# Ruby VM allocates 1 MB memory as a stack for a thread.
# 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|
Thread.new(client, queue, nil) do |pubsub, q, prev_err|
loop do
q << pubsub.next_event
prev_err = nil
rescue StandardError => e
next sleep 0.005 if e.instance_of?(prev_err.class) && e.message == prev_err&.message

q << e
prev_err = e
end
end
end
Expand Down Expand Up @@ -160,7 +164,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 6f40d8b

Please sign in to comment.