Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileTail never notices deleted file #22

Open
ebroder opened this issue Feb 7, 2013 · 3 comments
Open

FileTail never notices deleted file #22

ebroder opened this issue Feb 7, 2013 · 3 comments

Comments

@ebroder
Copy link

ebroder commented Feb 7, 2013

On Linux at least, FileTail handles rotated files correctly because it gets a moved notification. However, because inotify only notifies for file deletion when all file descriptors on the file are closed, FileTail is never notified when the file is flat out deleted (or, say, another file is renamed over the one being monitored). This means that the tailer hangs, even if the file is created again later.

Here's a fairly crude test case demonstrating the issue - note that the file tail fails to pick up the line written after the file is deleted and recreated ("bar"):

#!/usr/bin/env ruby

require 'fileutils'
require 'eventmachine-tail'

EM.run do
  FileUtils.touch('test')
  EM.file_tail('test') do |filetail, line|
    puts "Got line: #{line}"
  end

  EM.next_tick { File.open('test', 'a') {|f| f.puts("foo")} }

  EM.add_timer(1) do
    FileUtils.rm('test')
    EM.add_timer(1) do
      FileUtils.touch('test')
      File.open('test', 'a') {|f| f.puts("bar")}
      EM.add_timer(1) { EM.stop }
    end
  end
end
@jordansissel
Copy link
Owner

I recommend using filewatch instead of this library (jordansissel/ruby-filewatch). It doesn't use inotify due to its weird 'feature' behaviors and bugs in older linux kernels. It also works outside EM.

@swistaczek
Copy link

+1 Exception: < IOError: closed stream >

@swistaczek
Copy link

@jordansissel have you got any plans updating "delete" detection for this project? I have build CSV parser based on event machine and yours great work and it would be great if this project could benefit from ruby-filewatch (with EM suggar).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants