From 15293051b3c12ddd4ea46572f90e0fadb31bcb6c Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Wed, 31 Jan 2024 12:26:54 +0900 Subject: [PATCH] in_tail: Make closing io handler be done in closing phase And add consideration for concurrent execution. Signed-off-by: Daijiro Fukuda --- lib/fluent/plugin/in_tail.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index e4866e157b..514799a581 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -269,7 +269,13 @@ def shutdown # during shutdown phase, don't close io. It should be done in close after all threads are stopped. See close. stop_watchers(existence_path, immediate: true, remove_watcher: false) @tails_rotate_wait.keys.each do |tw| - detach_watcher(tw, @tails_rotate_wait[tw][:ino]) + # Note: Be careful about duplicate execution with the timer side. + # (There is no harm in duplicate execution, but need to be careful about nil exception, etc) + v = @tails_rotate_wait[tw] + next unless v + ino, timer = v.values + timer.detach rescue nil + detach_watcher(tw, ino, false) end @pf_file.close if @pf_file @@ -279,6 +285,7 @@ def shutdown def close super # close file handles after all threads stopped (in #close of thread plugin helper) + # It may be because we need to wait IOHanlder.ready_to_shutdown() close_watcher_handles end @@ -520,6 +527,9 @@ def close_watcher_handles tw.close end end + @tails_rotate_wait.keys.each do |tw| + tw.close + end end # refresh_watchers calls @tails.keys so we don't use stop_watcher -> start_watcher sequence for safety.