From e9b36c1435864da4e4bcf54991579ec5d3dc83c1 Mon Sep 17 00:00:00 2001 From: Gary Zhu Date: Wed, 31 May 2023 14:14:35 +0800 Subject: [PATCH 1/2] Check inode expectation to detach correct watcher when follow_inodes Signed-off-by: Gary Zhu Signed-off-by: garyzjq --- lib/fluent/plugin/in_tail.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index fb29dd249f..6c1d236df6 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -523,6 +523,11 @@ def update_watcher(target_info, pe) # so adding close_io argument to avoid this problem. # At shutdown, IOHandler's io will be released automatically after detached the event loop def detach_watcher(tw, ino, close_io = true) + if @follow_inodes && tw.ino != ino + log.warn("Skip detach_watcher because this is not the expected watcher to be detached", + path: tw.path, current_ino: tw.ino, expect_ino_to_close: ino) + return + end tw.watchers.each do |watcher| event_loop_detach(watcher) end From bcd9a1a3a04f897e5c48accd8550be3c948a83c6 Mon Sep 17 00:00:00 2001 From: garyzjq Date: Wed, 28 Jun 2023 13:39:40 +0800 Subject: [PATCH 2/2] only add warning log only when detect detaching a wrong watcher Signed-off-by: garyzjq --- lib/fluent/plugin/in_tail.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index 6c1d236df6..fc12e51890 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -524,9 +524,8 @@ def update_watcher(target_info, pe) # At shutdown, IOHandler's io will be released automatically after detached the event loop def detach_watcher(tw, ino, close_io = true) if @follow_inodes && tw.ino != ino - log.warn("Skip detach_watcher because this is not the expected watcher to be detached", - path: tw.path, current_ino: tw.ino, expect_ino_to_close: ino) - return + log.warn("detach_watcher could be detaching an unexpected tail_watcher with a different ino.", + path: tw.path, actual_ino_in_tw: tw.ino, expect_ino_to_close: ino) end tw.watchers.each do |watcher| event_loop_detach(watcher)