Skip to content

Commit

Permalink
Fix in_tail shutdown race condition problem
Browse files Browse the repository at this point in the history
  • Loading branch information
repeatedly committed Jun 13, 2014
1 parent aded271 commit 76f246a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def stop_watchers(paths, immediate = false, unwatched = false)
if tw
tw.unwatched = unwatched
if immediate
close_watcher(tw)
close_watcher(tw, false)
else
close_watcher_after_rotate_wait(tw)
end
Expand All @@ -173,8 +173,12 @@ def update_watcher(path, pe)
close_watcher_after_rotate_wait(rotated_tw) if rotated_tw
end

def close_watcher(tw)
tw.close
# TailWatcher#close is called by another thread at shutdown phase.
# It causes 'can't modify string; temporarily locked' error in IOHandler
# so adding close_io argument to avoid this problem.
# At shutdown, IOHandler's io will be released automatically after detached the event loop
def close_watcher(tw, close_io = true)
tw.close(close_io)
flush_buffer(tw)
if tw.unwatched && @pf
@pf[tw.path].update_pos(PositionFile::UNWATCHED_POSITION)
Expand Down Expand Up @@ -314,8 +318,8 @@ def detach
@stat_trigger.detach if @stat_trigger.attached?
end

def close
if @io_handler
def close(close_io = true)
if close_io && @io_handler
@io_handler.on_notify
@io_handler.close
end
Expand Down

0 comments on commit 76f246a

Please sign in to comment.