Skip to content

Commit

Permalink
Merge pull request #3275 from jgehrcke/jp/in_tail_stat_enoent
Browse files Browse the repository at this point in the history
in_tail: expect ENOENT during stat (try to fix #3274 and #3224)
  • Loading branch information
ashie committed Mar 4, 2021
2 parents 65a9edf + 419ef50 commit 4437fd9
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,17 @@ def expand_paths
(paths - excluded).select { |path|
FileTest.exist?(path)
}.each { |path|
target_info = TargetInfo.new(path, Fluent::FileWrapper.stat(path).ino)
if @follow_inodes
hash[target_info.ino] = target_info
else
hash[target_info.path] = target_info
# Even we just checked for existence, there is a race condition here as
# of which stat() might fail with ENOENT. See #3224.
begin
target_info = TargetInfo.new(path, Fluent::FileWrapper.stat(path).ino)
if @follow_inodes
hash[target_info.ino] = target_info
else
hash[target_info.path] = target_info
end
rescue Errno::ENOENT
$log.warn "expand_paths: stat() for #{path} failed with ENOENT. Skip file."
end
}
hash
Expand Down Expand Up @@ -406,8 +412,15 @@ def start_watchers(targets_info)
log.warn "Skip #{target_info.path} because unexpected setup error happens: #{e}"
next
end
target_info = TargetInfo.new(target_info.path, Fluent::FileWrapper.stat(target_info.path).ino)
@tails[target_info] = tw

begin
target_info = TargetInfo.new(target_info.path, Fluent::FileWrapper.stat(target_info.path).ino)
@tails[target_info] = tw
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)
end
}
end

Expand Down

0 comments on commit 4437fd9

Please sign in to comment.