From: Motohiro KOSAKI Date: 2011-05-18T20:36:02+09:00 Subject: [ruby-core:36313] [Ruby 1.9 - Bug #4283] Timeout.timeout may cause application exit unintetionally Issue #4283 has been updated by Motohiro KOSAKI. I've committed timeout-race-fix.patch as r31623 and I confirmed it fixes Charles's load test (ie https://github.com/jruby/jruby/blob/master/test/load/load_timeout.rb). I know it doesn't fix Ctrl-C issue. However I think we can discuss it separately. ---------------------------------------- Bug #4283: Timeout.timeout may cause application exit unintetionally http://redmine.ruby-lang.org/issues/4283 Author: Motohiro KOSAKI Status: Closed Priority: Normal Assignee: Yukihiro Matsumoto Category: lib Target version: 1.9.3 ruby -v: ruby 1.9.3dev (2010-12-22 trunk 30291) [x86_64-linux] =begin This issue was discovered during [Bug#4266] discussion. Current timeout is racy. Now, timeout module has following code. ------------------------------------------------------------------------------- def timeout() begin x = Thread.current y = Thread.start { begin sleep sec rescue => e x.raise e else x.raise exception, "execution expired" if x.alive? end } return yield(sec) rescue exception => e raise Error, e.message, e.backtrace ensure if y and y.alive? // (1) y.kill y.join # make sure y is dead. end end end ------------------------------------------------------------------------------- Then, A following race can occur. CPU0(thread x) CPU1(thread y) remark --------------------------------------------------------------------------- begin Thread.start sleep sec evaluate [user-defined-block] y.alive? return true wakeup from sleep x.raise Now, x is running at (1). Then ExitException which y raised can't be handled above rescue block. Then eventually, ExitException leak to caller and makes application exit. =end -- http://redmine.ruby-lang.org