Backport #8187

timeout doesn't interrupt assignment.

Added by Robert Gleeson about 1 year ago. Updated 12 months ago.

[ruby-core:53835]
Status:Rejected
Priority:Normal
Assignee:-

Description

Timeout does not interrupt & raise like usual with this example code:

require 'timeout'
Timeout.timeout(0.5) do
x = " "(2*31)
end

History

#1 Updated by Robert Gleeson about 1 year ago

I should have said that this code might exhaust your RAM, so don't let it run too long.

#2 Updated by Robert Gleeson about 1 year ago

For my case, this code was run in a subprocess. Instead of using Timeout in the subprocess, I use it from the parent instead, like this:

pid = fork { x = " "(2*31) }
begin
Timeout.timeout(1) do
Process.wait pid
end
rescue Timeout::Error
Process.kill 'SIGKILL', pid
Process.wait pid
end

This solves the problem for me.

#3 Updated by Robert Gleeson about 1 year ago

Tested against:
- ruby 1.9.3p194 (2012-04-20 revision 35410) [x8664-darwin11.4.2]
- ruby 2.0.0p0 (2013-02-24 revision 39474) [x86
64-darwin11.4.2]

The behavior on 1.9.3 is to hang without being able to interrupt, and the behavior
on 2.0.0 appears to execute the code, stop it, and exit without raising an exception.

#4 Updated by Robert Gleeson 12 months ago

I opened this bug on Rubinius(https://github.com/rubinius/rubinius/issues/2287) and it looks like there's no way to interrupt this code. Please close.

#5 Updated by Motohiro KOSAKI 12 months ago

I couldn't reproduce.

% ruby -v test.rb
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
/home/kosaki/ruby/git/test.rb:3: warning: assigned but unused variable - x
/home/kosaki/ruby/git/test.rb:3:in *': failed to allocate memory (NoMemoryError)
from /home/kosaki/ruby/git/test.rb:3:in
block in '
from /home/kosaki/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/timeout.rb:65:in timeout'
from /home/kosaki/ruby/git/test.rb:2:in
'

#6 Updated by Motohiro KOSAKI 12 months ago

  • Status changed from Open to Rejected

Also available in: Atom PDF