File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
lib/redis_client/cluster/concurrent_worker Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ module ConcurrentWorker
10
10
# It is a fixed size but we can modify the size with some environment variables.
11
11
# So it consumes memory 1 MB multiplied a number of workers.
12
12
class Pooled
13
+ IO_ERROR_NEVER = { IOError => :never } . freeze
14
+ IO_ERROR_ON_BLOCKING = { IOError => :on_blocking } . freeze
15
+ private_constant :IO_ERROR_NEVER , :IO_ERROR_ON_BLOCKING
16
+
13
17
def initialize ( size :)
14
18
raise ArgumentError , "size must be positive: #{ size } " unless size . positive?
15
19
@@ -65,7 +69,15 @@ def ensure_workers
65
69
66
70
def spawn_worker
67
71
Thread . new ( @q ) do |q |
68
- loop { q . pop . exec }
72
+ Thread . handle_interrupt ( IO_ERROR_NEVER ) do
73
+ loop do
74
+ Thread . handle_interrupt ( IO_ERROR_ON_BLOCKING ) do
75
+ q . pop . exec
76
+ end
77
+ end
78
+ end
79
+ rescue IOError
80
+ # stream closed in another thread
69
81
end
70
82
end
71
83
end
You can’t perform that action at this time.
0 commit comments