Use 'Interrupted' instead of IOError for interrupts

This commit is contained in:
Jordan Sissel 2013-01-03 12:02:00 -08:00
parent 313e78e200
commit 8ac413a792

View file

@ -11,6 +11,7 @@ require "timeout"
# Can either accept connections from clients or connect to a server,
# depending on `mode`.
class LogStash::Inputs::Tcp < LogStash::Inputs::Base
class Interrupted < StandardError; end
config_name "tcp"
plugin_status "beta"
@ -73,8 +74,6 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
:client => socket.peer)
end # begin
rescue IOError
# nothing
ensure
begin
socket.close
@ -108,10 +107,13 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
s.instance_eval { class << self; include ::LogStash::Util::SocketPeer end }
@logger.debug("Accepted connection", :client => s.peer,
:server => "#{@host}:#{@port}")
handle_socket(s, output_queue, "tcp://#{s.peer}/")
begin
handle_socket(s, output_queue, "tcp://#{s.peer}/")
rescue Interrupted
s.close rescue nil
end
end # Thread.start
rescue IOError
rescue IOError, Interrupted
if @interrupted
# Intended shutdown, get out of the loop
@server_socket.close
@ -139,7 +141,7 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
def teardown
if server?
@interrupted = true
@thread.raise(IOError.new)
@thread.raise(Interrupted.new)
end
end # def teardown
end # class LogStash::Inputs::Tcp