eventmachine-tail
eventmachine-tail copied to clipboard
FileTail never notices deleted file
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
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.
+1 Exception: < IOError: closed stream >
@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).