Skip to content

Commit

Permalink
in_tail: Make closing io handler be done in closing phase
Browse files Browse the repository at this point in the history
And add consideration for concurrent execution.

Signed-off-by: Daijiro Fukuda <[email protected]>
  • Loading branch information
daipom committed Jan 31, 2024
1 parent 341d8b8 commit 1529305
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 1529305

Please sign in to comment.