Project

General

Profile

Actions

Bug #4283

closed

Timeout.timeout may cause application exit unintetionally

Added by kosaki (Motohiro KOSAKI) almost 14 years ago. Updated about 12 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.3dev (2010-12-22 trunk 30291) [x86_64-linux]
Backport:
[ruby-core:34534]

Description

=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


Files

timeout-race-fix.patch (2.94 KB) timeout-race-fix.patch kosaki (Motohiro KOSAKI), 01/17/2011 01:53 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #4285: Ruby don't have asynchrounous exception safe syntax and It should have.Closedko1 (Koichi Sasada)01/17/2011Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0