The following code run on JRuby 9.1.17.0 and 9.2.13.0 on Windows:
at_exit { puts "at_exit function" }
ObjectSpace.define_finalizer("string", proc { puts "in finalizer" })
exit!
produces this:
at_exit function
in finalizer
My expectation was that the exit handlers should not have been called as per the documentation for exit!
:
https://ruby-doc.org/core-2.7.1/Kernel.html#method-i-exit-21
Is this a bug in exit!
?
Is there some other way that I can achieve the desired outcome of not firing exit handlers so that I can guarantee killing my system from the inside?
This looks like a known incompatibility in JRuby.
The specs for Kernel#exit!
and Process::exit!
were only added to ruby/spec
on July, 27th 2020 (35 days ago) by Benoit Daloze (maintainer of ruby/spec
, lead developer of TruffleRuby, JRuby Team Member): https://github.com/ruby/spec/commit/3bf0edcecb424df1e3a70fe48971b24af4be1977#diff-5b2f13aa6d64a30812e9221d9994b907R95-R99
On July, 28th 2020, Benoit added tags to the JRuby spec
directory disabling those new specs as known failures: https://github.com/jruby/jruby/commit/f138bd9e62b757e6fd209101b2eb46b266b9b7b0#diff-332fe3279d2469ab891d8739c3d425e3R1-R2
The JRuby team does run the ruby/spec
s to ensure compatibility with all other Ruby implementations, but of course if specs are missing, incompatibilities may slip through unnoticed.