Files
one/src/hem
Jan Orel 7e0fa890e3 B #-: Fix ZMQ shutdown SIGSEGV on Ruby 3.4 (frozen FFI objects) (#4103)
The previous fix (b001d61b) suppressed FFI::DynamicLibrary finalizers
via ObjectSpace.undefine_finalizer to prevent dlclose() from unmapping
libzmq while ZMQ I/O threads are still running. However, on Ruby 3.4+
(SLES 16), FFI::DynamicLibrary objects are frozen for Ractor-safety,
causing undefine_finalizer to raise FrozenError — silently failing.

Fix both shutdown crash paths:

  1) SIGSEGV (dlclose unmaps libzmq): pin libzmq in memory via
     Fiddle.dlopen with disable_close, adding a dlopen refcount that
     is never decremented. FFI's dlclose then drops the refcount to 1
     (not 0), keeping the library mapped.

  2) Deadlock (zmq_ctx_term blocks on open sockets): suppress the
     ZMQ::Context finalizer via undefine_finalizer (Context objects
     are not frozen, so this works on all Ruby versions).

Falls back to the old undefine_finalizer approach on systems without
Fiddle or with a different libzmq soname (works on Ruby < 3.4).
2026-03-16 16:10:11 +01:00
..
2026-02-12 09:24:59 +01:00