Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix race condition in stopping FSEvent runner #40

Merged
merged 1 commit into from

2 participants

@dbussink

The race condition 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.

@dbussink dbussink 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.
75f1b9c
@ttilley
Collaborator

Good catch. Thanks. :)

@ttilley ttilley merged commit fa8ad08 into thibaudgg:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 28, 2012
  1. @dbussink

    Handle potential race condition when stopping

    dbussink authored
    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.
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.