Project

General

Profile

Actions

Bug #22191

closed

`Signal.trap(:EXIT)` exception only shown if `at_exit` also raises

Bug #22191: `Signal.trap(:EXIT)` exception only shown if `at_exit` also raises

Added by Earlopain (Earlopain _) 3 days ago. Updated about 19 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 4.1.0dev (2026-05-29T14:34:40Z master 7a07a54298) +PRISM [x86_64-linux]
[ruby-core:126049]

Description

Signal.trap(:EXIT, proc { raise "foo" })
# No output
Signal.trap(:EXIT, proc { raise "foo" })
at_exit { raise "bar" }
# test.rb:2:in 'block in <main>': bar (RuntimeError)
# test.rb:1:in 'block in <main>': foo (RuntimeError)

A bit weird

Updated by nobu (Nobuyoshi Nakada) 2 days ago Actions #1

  • Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED

Updated by nobu (Nobuyoshi Nakada) 2 days ago Actions #2 [ruby-core:126062]

Related bug: when two END raise exceptions, the same message is printed multiple times.

$ ruby -e 'END{raise "END1"};END{raise "END2"}'
-e:1:in 'block (2 levels) in <main>': END2 (RuntimeError)
-e:1:in 'block (2 levels) in <main>': END1 (RuntimeError)
-e:1:in 'block (2 levels) in <main>': END2 (RuntimeError)
$ ruby -e 'END{raise "END1"};END{raise "END2"};END{raise "END3"}'
-e:1:in 'block (2 levels) in <main>': END3 (RuntimeError)
-e:1:in 'block (2 levels) in <main>': END2 (RuntimeError)
-e:1:in 'block (2 levels) in <main>': END3 (RuntimeError)
-e:1:in 'block (2 levels) in <main>': END1 (RuntimeError)
-e:1:in 'block (2 levels) in <main>': END2 (RuntimeError)
-e:1:in 'block (2 levels) in <main>': END3 (RuntimeError)

Updated by nobu (Nobuyoshi Nakada) 2 days ago Actions #3

  • Status changed from Open to Closed

Applied in changeset git|0d7e50a1746bfa3db2a50478d3680cd7c36ea383.


[Bug #22191] Report EXIT handler exceptions after END blocks

Keep exceptions raised by EXIT traps until END handlers finish.
That leaves them available for reporting during cleanup.

Print END handler exceptions without replaying causes already
reported from earlier exit handlers. This keeps the previous handler
exception visible while avoiding duplicate diagnostics.

Updated by k0kubun (Takashi Kokubun) about 19 hours ago Actions #4 [ruby-core:126082]

  • Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE
Actions

Also available in: PDF Atom