Skip to content

Commit 68cc454

Browse files
committed
Fix infinite loops in ressurrectionist / sniffer
1 parent b6060f4 commit 68cc454

File tree

1 file changed

+11
-9
lines changed
  • lib/logstash/outputs/elasticsearch/http_client

1 file changed

+11
-9
lines changed

lib/logstash/outputs/elasticsearch/http_client/pool.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@ def urls
9494
url_info.keys
9595
end
9696

97-
def until_stopped(task_name)
97+
def until_stopped(task_name, delay)
98+
last_done = Time.now
9899
until @state_mutex.synchronize { @stopping }
99100
begin
100-
yield
101+
now = Time.now
102+
if (now - last_done) >= delay
103+
last_done = now
104+
yield
105+
end
106+
sleep 1
101107
rescue => e
102108
logger.warn(
103109
"Error while performing #{task_name}",
@@ -111,7 +117,7 @@ def until_stopped(task_name)
111117

112118
def start_sniffer
113119
@sniffer = Thread.new do
114-
until_stopped("sniffing") { sniff! }
120+
until_stopped("sniffing", sniffer_delay) { sniff! }
115121
end
116122
end
117123

@@ -159,12 +165,8 @@ def sniffer_alive?
159165

160166
def start_resurrectionist
161167
@resurrectionist = Thread.new do
162-
last_resurrect = Time.now
163-
until_stopped("resurrection") do
164-
if Time.now-last_resurrect >= @resurrect_delay
165-
last_resurrect = Time.now
166-
resurrect_dead!
167-
end
168+
until_stopped("resurrection", @resurrect_delay) do
169+
resurrect_dead!
168170
end
169171
end
170172
end

0 commit comments

Comments
 (0)