From: "ivoanjo (Ivo Anjo) via ruby-core" Date: 2023-08-25T08:12:02+00:00 Subject: [ruby-core:114528] [Ruby master Feature#17678] Ractors do not restart after fork Issue #17678 has been updated by ivoanjo (Ivo Anjo). > The addition of Ractor#alive? and/or Ractor#status makes sense to me. Even in non-forked processes such methods could be useful. Note that you can get what you want already, by calling Ractor#inspect, so these methods would only need to expose information that Ractor is already storing. Thanks for looking into this! I don't think the info is there in #inspect... At least I don't get it on stable or latest ruby-head? ���� Here's an updated example: ```ruby puts RUBY_DESCRIPTION r2 = Ractor.new { puts "[#{Process.pid}] Ractor started!"; sleep(1000) } puts "[#{Process.pid}] In parent process, ractor status is #{r2.inspect}" sleep(1) puts "[#{Process.pid}] Forking..." fork do puts "[#{Process.pid}] In child process, ractor status is #{r2.inspect}" end Process.wait ``` and here's what I get: ``` $ ruby ractor-test.rb ruby 3.3.0dev (2023-08-24T12:12:51Z master 5ec1fc52c1) [x86_64-linux] ractor-test.rb:3: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. [10] In parent process, ractor status is # [10] Ractor started! [10] Forking... [12] In child process, ractor status is # ``` ---------------------------------------- Feature #17678: Ractors do not restart after fork https://bugs.ruby-lang.org/issues/17678#change-104327 * Author: ivoanjo (Ivo Anjo) * Status: Assigned * Priority: Normal * Assignee: ko1 (Koichi Sasada) ---------------------------------------- Hello there! I'm working at Datadog on the `ddtrace` gem -- and we're experimenting with using Ractors in our library but run into a few issues. ### Background When running a Ractor as a background process, the Ractor stops & does not restart when the application forks. ### How to reproduce (Ruby version & script) `ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]` ```ruby r2 = Ractor.new do loop { puts "[#{Process.pid}] Ractor"; sleep(1) } end sleep(1) puts "[#{Process.pid}] Forking..." fork do sleep(5) puts "[#{Process.pid}] End fork." end loop do sleep(1) end ``` ### Expectation and result The application prints ���Ractor��� each second in the main process, but not in the fork. Expected the Ractor (defined as `r2`) to run in the fork. ``` [29] Ractor [29] Ractor [29] Forking... [29] Ractor [29] Ractor [29] Ractor [29] Ractor [29] Ractor [32] End fork. [29] Ractor [29] Ractor [29] Ractor ``` ### Additional notes Threads do not restart across forks either, so it might not be unreasonable to expect consistent behavior. However, it���s possible to detect a dead Thread and recreate it after a fork (e.g. with `#alive?`, `#status`), but there���s no such mechanism for Ractors. ### Suggested solutions 1. Auto-restart Ractors after fork 2. Add additional methods to Ractors that allow users to check & manage the status of the Ractor, similar to Thread. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/