Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fix race condition in stopping FSEvent runner #40

Merged
merged 1 commit into from over 1 year ago

2 participants

Dirkjan Bussink Travis Tilley
Dirkjan Bussink

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.

Dirkjan Bussink 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
Travis Tilley
Collaborator

Good catch. Thanks. :)

Travis Tilley ttilley merged commit fa8ad08 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 28, 2012
Dirkjan Bussink 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
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 1 deletion. Show diff stats Hide diff stats

  1. +1 1  lib/rb-fsevent/fsevent.rb
2  lib/rb-fsevent/fsevent.rb
@@ -43,7 +43,7 @@ def run
43 43 callback.call(modified_dir_paths)
44 44 end
45 45 end
46   - rescue Interrupt, IOError
  46 + rescue Interrupt, IOError, Errno::EBADF
47 47 ensure
48 48 stop
49 49 end

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.