Skip to content

Commit

Permalink
Merge pull request #3328 from fluent/issue-3327
Browse files Browse the repository at this point in the history
in_tail: Fix an incorrect error handling on catching a short-lived log
  • Loading branch information
ashie committed Apr 13, 2021
2 parents 07df9a0 + 1c1ef8e commit 2613fcb
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 2613fcb

Please sign in to comment.