Skip to content

Commit

Permalink
in_tail: Fix an incorrect error handling
Browse files Browse the repository at this point in the history
This commit fixes the following error reported at #3327, it will occur
when a file is removed after calling setup_watcher and before
registering the created watcher.

  2021-04-12 16:00:21 -0700 [warn]: stat() for /var/log/containers/obfuscated_container_xxx_1.log failed with ENOENT. Drop tail watcher for now.
  2021-04-12 16:00:21 -0700 [error]: unexpected error error_class=NoMethodError error="undefined method `each_value' for #<Fluent::Plugin::TailInput::TargetInfo:0x00005641d5026828>\nDid you mean?  each_slice"
    2021-04-12 16:00:21 -0700 [error]: /usr/local/lib/ruby/gems/2.7.0/gems/fluentd-1.12.2/lib/fluent/plugin/in_tail.rb:428:in `stop_watchers'
    2021-04-12 16:00:21 -0700 [error]: /usr/local/lib/ruby/gems/2.7.0/gems/fluentd-1.12.2/lib/fluent/plugin/in_tail.rb:422:in `rescue in block in start_watchers'
    2021-04-12 16:00:21 -0700 [error]: /usr/local/lib/ruby/gems/2.7.0/gems/fluentd-1.12.2/lib/fluent/plugin/in_tail.rb:416:in `block in start_watchers'
    2021-04-12 16:00:21 -0700 [error]: /usr/local/lib/ruby/gems/2.7.0/gems/fluentd-1.12.2/lib/fluent/plugin/in_tail.rb:396:in `each_value'
    2021-04-12 16:00:21 -0700 [error]: /usr/local/lib/ruby/gems/2.7.0/gems/fluentd-1.12.2/lib/fluent/plugin/in_tail.rb:396:in `start_watchers'

Signed-off-by: Takuro Ashie <ashie@clear-code.com>
  • Loading branch information
ashie committed Apr 13, 2021
1 parent 4b1ee63 commit 1c1ef8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ def start_watchers(targets_info)
rescue Errno::ENOENT
$log.warn "stat() for #{target_info.path} failed with ENOENT. Drop tail watcher for now."
# explicitly detach and unwatch watcher `tw`.
stop_watchers(target_info, immediate: true, unwatched: true)
tw.unwatched = true
detach_watcher(tw, target_info.ino, false)
end
}
end
Expand Down
18 changes: 18 additions & 0 deletions test/plugin/test_in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1919,4 +1919,22 @@ def test_skip_refresh_on_startup
waiting(5) { sleep 0.1 until d.instance.instance_variable_get(:@tails).keys.size == 1 }
d.instance_shutdown
end

def test_ENOENT_error_after_setup_watcher
path = "#{TMP_DIR}/tail.txt"
FileUtils.touch(path)
config = config_element('', '', {
'format' => 'none',
})
d = create_driver(config)
mock.proxy(d.instance).setup_watcher(anything, anything) do |tw|
cleanup_file(path)
tw
end
assert_nothing_raised do
d.run(shutdown: false) {}
end
d.instance_shutdown
assert($log.out.logs.any?{|log| log.include?("stat() for #{path} failed with ENOENT. Drop tail watcher for now.\n") })
end
end

0 comments on commit 1c1ef8e

Please sign in to comment.