Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit 8203949

Browse files
committed
Log and continue rather than die when socket accept fails
Fixes logstash-plugins#59 Fixes logstash-plugins#84
1 parent ca696bf commit 8203949

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

lib/logstash/inputs/tcp.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def decode_buffer(client_ip_address, client_address, client_port, codec, proxy_a
189189

190190
private
191191

192+
RUN_LOOP_ERROR_MESSAGE="TCP input server encountered error"
192193
def run_ssl_server()
193194
while !stop?
194195
begin
@@ -199,9 +200,12 @@ def run_ssl_server()
199200
# log error, close socket, accept next connection
200201
@logger.debug? && @logger.debug("SSL Error", :exception => e, :backtrace => e.backtrace)
201202
rescue => e
202-
# if this exception occured while the plugin is stopping
203-
# just ignore and exit
204-
raise e unless stop?
203+
@logger.error(
204+
RUN_LOOP_ERROR_MESSAGE,
205+
:message => e.message,
206+
:class => e.class.name,
207+
:backtrace => e.backtrace
208+
)
205209
end
206210
end
207211
ensure

spec/inputs/tcp_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,41 @@
348348
end
349349
end
350350

351+
describe "an error occurs during an accept" do
352+
let(:socket) { double("socket").as_null_object }
353+
354+
before do
355+
allow(input).to receive(:server_socket).and_return(socket)
356+
357+
allow(socket).to receive(:accept) do |a1, a2, a3|
358+
raise StandardError, "blah"
359+
end
360+
end
361+
362+
it "should log the error on accept" do
363+
allow(input.logger).to receive(:error).with(any_args)
364+
365+
stop = Thread.new {
366+
sleep 2
367+
input.do_stop
368+
}
369+
expect do
370+
input.run(Queue.new)
371+
end.not_to raise_error
372+
373+
expect(input.logger).to have_received(:error).with(
374+
::LogStash::Inputs::Tcp::RUN_LOOP_ERROR_MESSAGE,
375+
:message => "blah",
376+
:class => "StandardError",
377+
:backtrace => anything
378+
).at_least(:once)
379+
380+
stop.join
381+
# Wait for stop to actually happen
382+
sleep 1
383+
end
384+
end
385+
351386
context "that sends garbage instead of TLS handshake" do
352387
let!(:input_task) { Stud::Task.new { input.run(queue) } }
353388
let(:max_length) { 1000 }

0 commit comments

Comments
 (0)