Skip to content
Prev Previous commit
Next Next commit
Fix: avoid using Timeout to be able to stop plugin
  • Loading branch information
kares committed Nov 22, 2021
commit f20f02472d15ba65c1ef543904f0c610d0037394
25 changes: 11 additions & 14 deletions lib/logstash/inputs/unix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def initialize(*params)
public
def register
require "socket"
require "timeout"

if server?
@logger.info("Starting unix input listener", :address => @path, :force_unlink => @force_unlink)
Expand Down Expand Up @@ -85,34 +84,32 @@ def handle_socket(socket, output_queue)
begin
hostname = Socket.gethostname
while !stop?
buf = nil
# NOTE(petef): the timeout only hits after the line is read
# or socket dies
# TODO(sissel): Why do we have a timeout here? What's the point?
if @data_timeout == -1
buf = socket.readpartial(16384)
else
Timeout::timeout(@data_timeout) do
buf = socket.readpartial(16384)
data = socket.read_nonblock(16384, exception: false)

if data == :wait_readable
if @data_timeout == -1 || IO.select([socket], nil, nil, @data_timeout)
retry # socket read operation
else
# socket not ready after @data_timeout seconds
@logger.info("Closing connection after read timeout", :path => @path)
return
end
end
@codec.decode(buf) do |event|

@codec.decode(data) do |event|
decorate(event)
event.set(@host_name_field, hostname) unless event.include?(@host_name_field)
event.set(@file_path_field, @path) unless event.include?(@file_path_field)
output_queue << event
end
end
rescue Timeout::Error
@logger.info("Closing connection after read timeout", :path => @path)
rescue => e
if @logger.debug?
@logger.debug("Closing connection", :path => @path, :exception => e, :backtrace => e.backtrace)
else
@logger.info("Closing connection", :path => @path, :exception => e)
end
end

ensure
begin
socket.close
Expand Down