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: Fix an incorrect error handling on catching a short-lived log #3328

Merged
merged 1 commit into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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