Skip to content

Commit

Permalink
Some timers were possibly still left running. Fixed.
Browse files Browse the repository at this point in the history
Make sure all timers are canceled.
  • Loading branch information
johnae committed Aug 29, 2011
1 parent 4fdd764 commit f7ef1f7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/em/filetail.rb
Expand Up @@ -81,6 +81,8 @@ def initialize(path, startpos=-1, &block)
@want_reopen = false
@reopen_on_eof = false
@symlink_timer = nil
@missing_file_check_timer = nil
@read_timer = nil
@symlink_target = nil
@symlink_stat = nil

Expand Down Expand Up @@ -203,9 +205,12 @@ def open
public
def close
@closed = true
@want_read = false
EM.schedule do
@watch.stop_watching if @watch
@read_timer.cancel if @read_timer
@symlink_timer.cancel if @symlink_timer
@missing_file_check_timer.cancel if @missing_file_check_timer
@file.close if @file
end
end # def close
Expand Down Expand Up @@ -255,7 +260,7 @@ def watch_symlink(&block)
def schedule_next_read
if !@want_read
@want_read = true
EventMachine::add_timer(@naptime) do
@read_timer = EventMachine::add_timer(@naptime) do
@want_read = false
read
end
Expand Down Expand Up @@ -330,12 +335,12 @@ def handle_eof
rescue Errno::ENOENT
# The file disappeared. Wait for it to reappear.
# This can happen if it was deleted or moved during log rotation.
timer = EM::PeriodicTimer.new(@missing_file_check_interval) do
@missing_file_check_timer = EM::PeriodicTimer.new(@missing_file_check_interval) do
begin
read_file_metadata do |filestat, linkstat, linktarget|
handle_fstat(filestat, linkstat, linktarget)
end
timer.cancel
@missing_file_check_timer.cancel
rescue Errno::ENOENT
# The file disappeared. Wait for it to reappear.
# This can happen if it was deleted or moved during log rotation.
Expand Down

0 comments on commit f7ef1f7

Please sign in to comment.