Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/redis_client/cluster/concurrent_worker/pooled.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module ConcurrentWorker
# So it consumes memory 1 MB multiplied a number of workers.
class Pooled
IO_ERROR_NEVER = { IOError => :never }.freeze
IO_ERROR_ON_BLOCKING = { IOError => :on_blocking }.freeze
private_constant :IO_ERROR_NEVER, :IO_ERROR_ON_BLOCKING
IO_ERROR_IMMEDIATE = { IOError => :immediate }.freeze
private_constant :IO_ERROR_NEVER, :IO_ERROR_IMMEDIATE

def initialize(size:)
raise ArgumentError, "size must be positive: #{size}" unless size.positive?
Expand Down Expand Up @@ -73,7 +73,7 @@ def spawn_worker
Thread.new(@q) do |q|
Thread.handle_interrupt(IO_ERROR_NEVER) do
loop do
Thread.handle_interrupt(IO_ERROR_ON_BLOCKING) do
Thread.handle_interrupt(IO_ERROR_IMMEDIATE) do
q.pop.exec
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/redis_client/cluster/pub_sub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Cluster
class PubSub
class State
IO_ERROR_NEVER = { IOError => :never }.freeze
IO_ERROR_ON_BLOCKING = { IOError => :on_blocking }.freeze
private_constant :IO_ERROR_NEVER, :IO_ERROR_ON_BLOCKING
IO_ERROR_IMMEDIATE = { IOError => :immediate }.freeze
private_constant :IO_ERROR_NEVER, :IO_ERROR_IMMEDIATE

def initialize(client, queue)
@client = client
Expand Down Expand Up @@ -45,12 +45,12 @@ def spawn_worker(client, queue)
Thread.new(client, queue, nil) do |pubsub, q, prev_err|
Thread.handle_interrupt(IO_ERROR_NEVER) do
loop do
Thread.handle_interrupt(IO_ERROR_ON_BLOCKING) { q << pubsub.next_event }
Thread.handle_interrupt(IO_ERROR_IMMEDIATE) { 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

Thread.handle_interrupt(IO_ERROR_ON_BLOCKING) { q << e }
Thread.handle_interrupt(IO_ERROR_IMMEDIATE) { q << e }
prev_err = e
end
end
Expand Down