Project

General

Profile

Bug #14566

`raise` in `Exception#message` causes infinite loop

Added by pocke (Masataka Kuwabara) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.0dev (2018-03-01 trunk 62592) [x86_64-linux]
[ruby-core:<unknown>]

Description

This code does not stop.

class A < StandardError
  def message
    raise
  end
end

raise A

The following code also does not stop.

class A < StandardError
  def message
    1/0
  end
end

raise A

And they ignore CTRL-C, so I should do CTRL-Z (suspend) and kill -9 to stop them.

I confirmed the problem in Ruby 2.5 and trunk.

$ ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]

$ ruby -v
ruby 2.6.0dev (2018-03-01 trunk 62592) [x86_64-linux]

But Ruby 2.4 and 2.3 do not stop (I does not have Ruby 2.2 because I cannot build it in my environment.).
I can get same outputs between raise and 1/0 in the message method body.

$ ruby -v test.rb
ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-linux]
test.rb:7:in `<main>': A

$ ruby -v test.rb
ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-linux]
test.rb:7:in `<main>': A

Files

fix-bug-14566.patch (1.75 KB) fix-bug-14566.patch ujihisa (Tatsuhiro Ujihisa), 04/10/2018 12:55 PM

Associated revisions

Revision aa2b32ae
Added by nobu (Nobuyoshi Nakada) over 1 year ago

eval_error.c: fix loop on exception in message

  • error.c (rb_get_message): accessor to the message.

  • eval_error.c (rb_ec_error_print): handle exceptions on fetching
    the message. [Bug #14566]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 63133
Added by nobu (Nobuyoshi Nakada) over 1 year ago

eval_error.c: fix loop on exception in message

  • error.c (rb_get_message): accessor to the message.

  • eval_error.c (rb_ec_error_print): handle exceptions on fetching
    the message. [Bug #14566]

Revision 63133
Added by nobu (Nobuyoshi Nakada) over 1 year ago

eval_error.c: fix loop on exception in message

  • error.c (rb_get_message): accessor to the message.

  • eval_error.c (rb_ec_error_print): handle exceptions on fetching
    the message. [Bug #14566]

Revision 78e4b57c
Added by nagachika (Tomoyuki Chikanaga) over 1 year ago

merge revision(s) 63133: [Backport #14566]

    eval_error.c: fix loop on exception in message

    * error.c (rb_get_message): accessor to the message.

    * eval_error.c (rb_ec_error_print): handle exceptions on fetching
      the message.  [Bug #14566]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@64319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 64319
Added by nagachika (Tomoyuki Chikanaga) over 1 year ago

merge revision(s) 63133: [Backport #14566]

eval_error.c: fix loop on exception in message

* error.c (rb_get_message): accessor to the message.

* eval_error.c (rb_ec_error_print): handle exceptions on fetching
  the message.  [Bug #14566]

History

Updated by ujihisa (Tatsuhiro Ujihisa) over 1 year ago

I tried making a patch fixing this issue. See attached.
This patch makes the behaviour similar to the old Ruby, rescuing any exceptions in the "message" method, but also warns that an exception was automatically caught.

I'm not 100% sure if this is the solution that everyone wants. Also the test in the patch needs an update; I wasn't sure how to make sure if it's not causing infinite loop. I just left a draft as a comment there.

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

Thank you, I've missed the report mail.
I think it fatal.

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED

It should work as well as 2.4, not fatal.

#4

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63133.


eval_error.c: fix loop on exception in message

  • error.c (rb_get_message): accessor to the message.

  • eval_error.c (rb_ec_error_print): handle exceptions on fetching
    the message. [Bug #14566]

Updated by nagachika (Tomoyuki Chikanaga) over 1 year ago

  • Backport changed from 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: DONE

ruby_2_5 r64319 merged revision(s) 63133.

Also available in: Atom PDF