Issue #15766 has been updated by christian.boos / free.fr (Christian Boos).


It is indeed an exact duplicate of #15282, which you backported to 2.5.

However, you didn't backport it then to 2.4. I understand that now it's probably a bit too late for a backport.

Nevertheless, as I didn't see you closing this bug till now, I tried in the meantime to backport it myself (the fix for ruby_2_5 doesn't apply in a straightforward way to ruby_2_4).

In case anyone's interested, here's what I came up with:

```diff
diff --git a/eval.c b/eval.c
index 8be12ecd84..6a432ff4b7 100644
--- a/eval.c
+++ b/eval.c
@@ -502,14 +502,15 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
     else if (special_exception_p(th, mesg)) {
        mesg = ruby_vm_special_exception_copy(mesg);
     }
-    if (cause != Qundef) {
-       exc_setup_cause(mesg, cause);
-    }
-    else if (nocause) {
-       exc_setup_cause(mesg, Qnil);
+    if (cause == Qundef) {
+       if (nocause) {
+           cause = Qnil;
+       } else if (!rb_ivar_defined(mesg, id_cause)) {
+           cause = get_thread_errinfo(th);
+       }
     }
-    else if (!rb_ivar_defined(mesg, id_cause)) {
-       exc_setup_cause(mesg, get_thread_errinfo(th));
+    if (cause != Qundef && (NIL_P(cause) || !THROW_DATA_P(cause))) {
+       exc_setup_cause(mesg, cause);
     }

     file = rb_source_loc(&line);
```




----------------------------------------
Bug #15766: Crash in 2.4, 2.5 involving at_exit
https://bugs.ruby-lang.org/issues/15766#change-77759

* Author: christian.boos / free.fr (Christian Boos)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: REQUIRED, 2.5: DONE, 2.6: DONTNEED
----------------------------------------
Hello,

I've written a piece of code which reproducibly triggers a crash in some versions of Ruby (2.4 and 2.5, but not 2.2, 2.3 nor 2.6).

As this involves Minitest, I've started by filing a bug report on GitHub:

  https://github.com/seattlerb/minitest/issues/789

However, as this triggers a crash, I've been advised to report it here as well. Also, I wasn't able to find a similar bug report.

I have not looked too deep, but it seems that the way Minitest deals with `atexit` handlers exposes a problem when there's a pending `LocalJumpError`.

You will find all the details in the Minitest bug 789, but let me summarize them again here:

```ruby
require 'minitest/autorun'
require 'minitest/spec'

describe 'a simple crash reproducer' do
  before { return } # /!\
  it 'checks stuff' do
  end
end
```

Executing the above with the default minitest (or any newer version) won't work as a local return is not expected from within a `before` call (same thing for `after`).

But depending on the version, we may get a crash in addition to the error report:
 - `ruby 2.2.5p319 (2016-04-26 revision 54774) [x64-mingw32]` => `LocalJumpError: unexpected return` (no crash)
 - `ruby 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32]` => `LocalJumpError: unexpected return` (no crash)
 - `ruby 2.4.2p198 (2017-09-14 revision 59899) [x64-mingw32]` => `unexpected return` (+ CRASH)
 - `ruby 2.4.5p335 (2018-10-18 revision 65137) [x64-mingw32]` => `unexpected return` (+ CRASH)
 - `ruby 2.5.0p0 (2017-12-25 revision 61468) [x64-mingw32]` => `unexpected return` (+ CRASH)
 - `ruby 2.5.3p105 (2018-10-18 revision 65156) [x64-mingw32]` => `unexpected return` (+ CRASH)
 - `ruby 2.6.0p0 (2018-12-25 revision 66547) [x64-mingw32]` => `unexpected return` (no crash)
 - `ruby 2.6.1p33 (2019-01-30 revision 66950) [x64-mingw32]` => `unexpected return` (no crash)

I'm mainly developing on Windows, and use the pre-built versions from rubyinstaller.org,
but in order to be sure that this is *not* a Windows-specific issue, I also tried Ruby 2.5.0p0 and 2.5.1p57 on Linux and I get the same crash.

That crash always takes the same form:

```
D:/Workspace/install/windows64/ruby-2.4/lib/ruby/gems/2.4.0/gems/minitest-5.10.3/lib/minitest.rb:60: [BUG] Segmentation fault

-- Control frame information -----------------------------------------------
c:0003 p:---- s:0011 e:000010 CFUNC  :exit
c:0002 p:0027 s:0006 e:000005 BLOCK  D:/Workspace/install/windows64/ruby-2.4/lib/ruby/gems/2.4.0/gems/minitest-5.10.3/lib/minitest.rb:60 [FINISH]
c:0001 p:0000 s:0003 E:000520 (none) [FINISH]
```

As the problem doesn't happen with 2.6, I did hope that this problem would also be fixed in recent 2.4 and 2.5, but the problem is still present for 2.4.5p335 and 2.5.3p105 at least (latest versions from rubyinstaller.org).



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>