mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
- handle teardown
This commit is contained in:
parent
8de740e17a
commit
f353b7aff5
1 changed files with 9 additions and 3 deletions
|
@ -93,10 +93,12 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|||
public
|
||||
def run(output_queue)
|
||||
if server?
|
||||
@thread = Thread.current
|
||||
@client_threads = []
|
||||
loop do
|
||||
# Start a new thread for each connection.
|
||||
begin
|
||||
Thread.start(@server_socket.accept) do |s|
|
||||
@client_threads << Thread.start(@server_socket.accept) do |s|
|
||||
# TODO(sissel): put this block in its own method.
|
||||
|
||||
# monkeypatch a 'peer' method onto the socket.
|
||||
|
@ -108,7 +110,11 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|||
end # Thread.start
|
||||
rescue IOError
|
||||
if @interrupted
|
||||
#Intended shutdown, get out of the loop
|
||||
# Intended shutdown, get out of the loop
|
||||
@server_socket.close
|
||||
@client_threads.each do |thread|
|
||||
thread.raise(IOError.new)
|
||||
end
|
||||
break
|
||||
else
|
||||
# Else it was a genuine IOError caused by something else, so propagate it up..
|
||||
|
@ -130,7 +136,7 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|||
def teardown
|
||||
if server?
|
||||
@interrupted = true
|
||||
@server_socket.close
|
||||
@thread.raise(IOError.new)
|
||||
end
|
||||
end # def teardown
|
||||
end # class LogStash::Inputs::Tcp
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue