Bug #7180

set_trace_func with error in proc block locks up Ruby with 100% cpu usage and no way to exit without killing proc

Added by Gary Weaver over 2 years ago. Updated over 2 years ago.

[ruby-core:48053]
Status:Closed
Priority:Normal
Assignee:Koichi Sasada
ruby -v:ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0] Backport:

Description

Causes 100% cpu usage and cannot ctrl-C to exit (have to kill proc):

set_trace_func proc {|event, file, line, id, binding, classname| raise "error"}

Understand that set_trace_func plays by different rules, but this isn't expected.

History

#1 Updated by Gary Weaver over 2 years ago

One workaround:

l = lambda {|event, file, line, id, binding, classname| eval "def invalid syntax"}
set_trace_func proc {|event, file, line, id, binding, classname| begin;l.call(event, file, line, id, binding, classname);rescue SystemExit,Interrupt;raise;rescue Exception;end}

Would it be good to add to the rdoc for set_trace_func to indicate that the user should consider using this method if there is any chance it might raise an Exception other than SystemExit or Interrupt?

#2 Updated by Eric Hodel over 2 years ago

  • Category set to core
  • Status changed from Open to Feedback

=begin
I can't reproduce this. Can you provide a way to reproduce it?

With trunk:

$ time ruby20 -ve 'set_trace_func proc {|event, file, line, id, binding, classname| raise "error"}; loop do 1 + 1 end'
ruby 2.0.0dev (2012-09-06 trunk 36915) [x86_64-darwin12.1.0]
-e:1:in block in <main>': error (RuntimeError)
from -e:1:in
'

real 0m0.017s
user 0m0.012s
sys 0m0.004s

With ruby 1.9.4-p194 as you are running:

$ time ruby19 -ve 'set_trace_func proc {|event, file, line, id, binding, classname| raise "error"}; loop do 1 + 1 end'
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.2.0]
-e:1:in block in <main>': error (RuntimeError)
from -e:1:in
'

real 0m0.017s
user 0m0.012s
sys 0m0.004s

=end

#3 Updated by Yusuke Endoh over 2 years ago

  • Target version set to 2.0.0

Gary Weaver, ping?

Yusuke Endoh mame@tsg.ne.jp

#4 Updated by Yusuke Endoh over 2 years ago

  • Priority changed from Normal to 3

#5 Updated by Koichi Sasada over 2 years ago

The following script also repeat "[:return, 1]".
I'm not sure it is same problem or not.

def m
p:m
end

TracePoint.trace(:call, :return){|tp| p [tp.event, tp.line]; raise "bar"}
m

#6 Updated by Charlie Somerville over 2 years ago

This can be reproduced inside eval:

eval 'set_trace_func proc {|event, file, line, id, binding, classname| raise "error"}'

Edit: It seems this can be repro'd whenever there is a parent control frame.

#7 Updated by Koichi Sasada over 2 years ago

  • Status changed from Feedback to Closed
  • Assignee set to Koichi Sasada

Maybe r38331 (nobu's commit) solves this issue.

Also available in: Atom PDF