jordansissel / eventmachine-tail

Ruby EventMachine file tailing and friends. 'gem install eventmachine-tail' to install.
127 stars 16 forks source link

Fixing race condition when watching symlinks that change frequently #25

Closed juliettepaul closed 8 years ago

juliettepaul commented 8 years ago

When watching symlinks that change frequently this code would be unable to lstat the symlink even though the stat succeeded. I tightened this lookup to happen faster after stat and I also used the symlink? check on the return from stat instead of another File call to reduce the frequency of this race condition.

Reproduction: Watch a symlink in tmp created like this:

touch /tmp/test_target ; ln -sf /tmp/test_target /tmp/test_link

Run this command to replace the symlink constantly and watch your tailer throw an exception while trying to grab the inode:

while true; do rm -f /tmp/test_link; touch /tmp/test_target; ln -sf /tmp/test_target /tmp/test_link; done

You will get an exception similar to this:

/usr/etsy/deployinator/vendor/bundle/ruby/1.9.1/gems/eventmachine-tail-0.6.4/lib/em/filetail.rb:388:in `handle_fstat': undefined method `ino' for nil:NilClass (NoMethodError)
jordansissel commented 8 years ago

I no longer maintain this project (I haven't used EventMachine in many years). The code change looks OK to me.

juliettepaul commented 8 years ago

@jordansissel Does anyone maintain it? Would like to get a release up on rubygems for people experiencing this issue. I could upload the gem if you no longer want to maintain it just would need to get access on rubygems.org

jordansissel commented 8 years ago

@jayson I'm happy to add you as a contributor to this repo and give you ownership on rubygems to publish gems - let me know what you want :)

For rubygems, I only need your rubygems email and I can give you ownership.

juliettepaul commented 8 years ago

@jordansissel Sounds perfect. I can take over maintaining it.

My email is jaysonpaul@gmail.com

jordansissel commented 8 years ago
% gem owner eventmachine-tail -a ...
Owner added successfully.

Done! :)

juliettepaul commented 8 years ago

Thanks!

juliettepaul commented 8 years ago

@jordansissel Did you add me as a contributor for this repo as well so I can push here? Thanks!

juliettepaul commented 8 years ago

Looks like I got it thanks again