Skip to content

Commit 6f40d8b

Browse files
authored
fix: the behavior of subscription in pubsub when nodes are unstable (#396)
1 parent b9b3b71 commit 6f40d8b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/redis_client/cluster/pub_sub.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ def spawn_worker(client, queue)
3535
# Ruby VM allocates 1 MB memory as a stack for a thread.
3636
# It is a fixed size but we can modify the size with some environment variables.
3737
# So it consumes memory 1 MB multiplied a number of workers.
38-
Thread.new(client, queue) do |pubsub, q|
38+
Thread.new(client, queue, nil) do |pubsub, q, prev_err|
3939
loop do
4040
q << pubsub.next_event
41+
prev_err = nil
4142
rescue StandardError => e
43+
next sleep 0.005 if e.instance_of?(prev_err.class) && e.message == prev_err&.message
44+
4245
q << e
46+
prev_err = e
4347
end
4448
end
4549
end
@@ -160,7 +164,6 @@ def start_over
160164
@router.renew_cluster_state
161165
@state_dict.each_value(&:close)
162166
@state_dict.clear
163-
@queue.clear
164167
@commands.each { |command| _call(command) }
165168
break
166169
rescue ::RedisClient::ConnectionError, ::RedisClient::Cluster::NodeMightBeDown

0 commit comments

Comments
 (0)