guard/rb-inotify

Cycles of symlinks cause infinite loop/recursion

akerbos opened this issue · 4 comments

When used in combination with guard/listen, cycles of symlinks cause nontermination. I don't quite know whether the reason lies here or in listen.

See also here.

nex3 commented

Can you reproduce this with rb-inotify alone?

I think I have run into this with no guard/listen involved. The following code triggers the issue (tested on Ubuntu Trusty, with both rb-inotify 0.9.2 and 0.9.7, on Linux kernel 3.13.0 and ruby 2.0).

#!/usr/bin/ruby2.0
# -*- coding: utf-8 -*-

require 'rb-inotify'

notifier = INotify::Notifier.new

events = [ :dont_follow, :recursive, ]
path   = '/proc/self'

notifier.watch(path, *events) do |event|
  puts "Got event at: #{ event.absolute_name }"
end

The process gets into an apparent infinite loop, going through paths such as /proc/self/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/8/task/28712/fd/9/28713/root/sys/devices/system/memory/memory53/power

I do not think :recursive should behave this way, and especially :dont_follow should prevent that. A link to "/" is enough, it does not have to go through "/proc", but if "/proc" is mounted I think that will happen anyway.

I suppose the RECURSIVE_BLACKLIST in code is meant to guard against this somehow, but it is not effective.

This change appears to fix it: #60

Can you confirm this is fixed?

Running the example provided by @juhaerk seems to work correctly.