Permalink
Browse files

Handle potential race condition when stopping

The race conditionn is the following. When a FSEvent#stop is called, it
kills the child process and closes the pipe. It can happen that the kill
signal is sent and then succesfully the pipe is closed, before the child
process dies and the pipe in the parent is closed.

This means that IO::select() can raise a Errno::EBADF if the file
descriptor is closed while waiting in select(). This additional rescue
makes sure we shutdown in this case just like any others. This is a much
more reliable solution than adding for example a sleep() between
Process.kill and @pipe.close in FSEvent#stop.

Found because of rubinius/rubinius#2102.
  • Loading branch information...
1 parent d9481b5 commit 75f1b9cd9d75fe8d76725d7a268f1a52f401ba69 @dbussink dbussink committed Dec 28, 2012
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/rb-fsevent/fsevent.rb
View
2 lib/rb-fsevent/fsevent.rb
@@ -43,7 +43,7 @@ def run
callback.call(modified_dir_paths)
end
end
- rescue Interrupt, IOError
+ rescue Interrupt, IOError, Errno::EBADF
ensure
stop
end

0 comments on commit 75f1b9c

Please sign in to comment.