Project

General

Profile

Actions

Bug #17678

open

Ractors do not restart after fork

Added by ivoanjo (Ivo Anjo) 5 months ago. Updated 5 months ago.

Status:
Assigned
Priority:
Normal
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
[ruby-core:102776]
Tags:

Description

Hello there! I'm working at Datadog on the ddtrace gem -- https://github.com/DataDog/dd-trace-rb 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]

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.
Actions #1

Updated by ivoanjo (Ivo Anjo) 5 months ago

  • ruby -v set to ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

Updated by hsbt (Hiroshi SHIBATA) 5 months ago

  • Assignee set to ko1 (Koichi Sasada)
  • Status changed from Open to Assigned
Actions #3

Updated by hsbt (Hiroshi SHIBATA) 5 months ago

  • Tags set to ractor
Actions

Also available in: Atom PDF