From 1517ef8a8bca73422841abd71cc3cbc7fa56d37a Mon Sep 17 00:00:00 2001 From: Taishi Kasuga Date: Mon, 14 Oct 2024 08:14:37 +0900 Subject: [PATCH] fix: change the behavior of subscription in pubsub when the node is unstable --- lib/redis_client/cluster/pub_sub.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/redis_client/cluster/pub_sub.rb b/lib/redis_client/cluster/pub_sub.rb index 80338c8..0719fdd 100644 --- a/lib/redis_client/cluster/pub_sub.rb +++ b/lib/redis_client/cluster/pub_sub.rb @@ -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 @@ -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