Project

General

Profile

Actions

Feature #19627

closed

Ensure the VM is alive before accessing objspace in C API

Added by ianks (Ian Ker-Seymer) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:113386]

Description

Currently, there is no supported way to check if the Ruby VM has been shut down. There are a couple of workarounds that I know of:

  1. Setup an exit handler which sets a global variable (like I did in https://github.com/tmm1/stackprof/pull/200).
  2. In Ruby 2.4 thru 3.2, you could check the hidden ruby_vm_global_ptr != NULL.

For my use, in rb-sys there is a feature to automatically report Rust memory allocations via rb_gc_adjust_memory_usage. However, there is a bug that can cause processes to deadlock and/or segfault if a Rust destructor gets called after the VM quits (which can happen in Rust background threads). Currently, I don’t think there’s a way to safely make this feature work. (https://github.com/oxidize-rb/rb-sys/pull/205)

It would be nice to have an official way to know if the Ruby VM is available, basically just a ruby_current_vm_ptr != null. Thoughts?

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0