Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_tail: Skip setup failed watcher to avoid resource leak and log bloat. ref #1696 #1742

Merged
merged 1 commit into from
Nov 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ class TailInput < Fluent::Plugin::Input

helpers :timer, :event_loop, :parser, :compat_parameters

class WatcherSetupError < StandardError
def initialize(msg)
@message = msg
end

def to_s
@message
end
end

FILE_PERMISSION = 0644

def initialize
Expand Down Expand Up @@ -250,6 +260,12 @@ def setup_watcher(path, pe)
event_loop_attach(watcher.stat_trigger)
end
tw
rescue => e
if tw
tw.detach
tw.close
end
raise e
end

def start_watchers(paths)
Expand All @@ -266,7 +282,13 @@ def start_watchers(paths)
end
end

@tails[path] = setup_watcher(path, pe)
begin
tw = setup_watcher(path, pe)
rescue WatcherSetupError => e
log.warn "Skip #{path} because unexpected setup error happens: #{e}"
next
end
@tails[path] = tw
}
end

Expand Down Expand Up @@ -480,8 +502,8 @@ def attach
end

def detach
@timer_trigger.detach if @enable_watch_timer && @timer_trigger.attached?
@stat_trigger.detach if @stat_trigger.attached?
@timer_trigger.detach if @enable_watch_timer && @timer_trigger && @timer_trigger.attached?
@stat_trigger.detach if @stat_trigger && @stat_trigger.attached?
@io_handler.on_notify if @io_handler
end

Expand Down Expand Up @@ -698,6 +720,9 @@ def open
io = Fluent::FileWrapper.open(@watcher.path)
io.seek(@watcher.pe.read_pos + @fifo.bytesize)
io
rescue RangeError
io.close if io
raise WatcherSetupError, "seek error with #{@watcher.path}: file position = #{@watcher.pe.read_pos.to_s(16)}, reading bytesize = #{@fifo.bytesize.to_s(16)}"
rescue Errno::ENOENT
nil
end
Expand All @@ -715,6 +740,9 @@ def with_io
@io ||= open
yield @io
end
rescue WatcherSetupError => e
close
raise e
rescue
@watcher.log.error $!.to_s
@watcher.log.error_backtrace
Expand Down