* [ruby-core:102776] [Ruby master Bug#17678] Ractors do not restart after fork
@ 2021-03-08 16:19 knuckles
2021-03-09 0:42 ` [ruby-core:102784] " hsbt
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: knuckles @ 2021-03-08 16:19 UTC (permalink / raw)
To: ruby-core
Issue #17678 has been reported by ivoanjo (Ivo Anjo).
----------------------------------------
Bug #17678: Ractors do not restart after fork
https://bugs.ruby-lang.org/issues/17678
* Author: ivoanjo (Ivo Anjo)
* Status: Open
* Priority: Normal
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
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]`
```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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:102784] [Ruby master Bug#17678] Ractors do not restart after fork
2021-03-08 16:19 [ruby-core:102776] [Ruby master Bug#17678] Ractors do not restart after fork knuckles
@ 2021-03-09 0:42 ` hsbt
2023-08-24 21:12 ` [ruby-core:114513] [Ruby master Feature#17678] " jeremyevans0 (Jeremy Evans) via ruby-core
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: hsbt @ 2021-03-09 0:42 UTC (permalink / raw)
To: ruby-core
Issue #17678 has been updated by hsbt (Hiroshi SHIBATA).
Assignee set to ko1 (Koichi Sasada)
Status changed from Open to Assigned
----------------------------------------
Bug #17678: Ractors do not restart after fork
https://bugs.ruby-lang.org/issues/17678#change-90801
* Author: ivoanjo (Ivo Anjo)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
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]`
```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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:114513] [Ruby master Feature#17678] Ractors do not restart after fork
2021-03-08 16:19 [ruby-core:102776] [Ruby master Bug#17678] Ractors do not restart after fork knuckles
2021-03-09 0:42 ` [ruby-core:102784] " hsbt
@ 2023-08-24 21:12 ` jeremyevans0 (Jeremy Evans) via ruby-core
2023-08-25 8:12 ` [ruby-core:114528] " ivoanjo (Ivo Anjo) via ruby-core
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2023-08-24 21:12 UTC (permalink / raw)
To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)
Issue #17678 has been updated by jeremyevans0 (Jeremy Evans).
Tracker changed from Bug to Feature
ruby -v deleted (ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux])
Backport deleted (2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN)
As Ractors always use separate OS threads, and fork only runs the current thread in the forked process, I don't see a way for Ractors to continue where they left off after fork. I think auto-starting would likely be a bad idea, because auto-starting would not return them to the state they were at fork.
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.
----------------------------------------
Feature #17678: Ractors do not restart after fork
https://bugs.ruby-lang.org/issues/17678#change-104304
* Author: ivoanjo (Ivo Anjo)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
----------------------------------------
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]`
```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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:114528] [Ruby master Feature#17678] Ractors do not restart after fork
2021-03-08 16:19 [ruby-core:102776] [Ruby master Bug#17678] Ractors do not restart after fork knuckles
2021-03-09 0:42 ` [ruby-core:102784] " hsbt
2023-08-24 21:12 ` [ruby-core:114513] [Ruby master Feature#17678] " jeremyevans0 (Jeremy Evans) via ruby-core
@ 2023-08-25 8:12 ` ivoanjo (Ivo Anjo) via ruby-core
2023-08-25 14:35 ` [ruby-core:114538] [Ruby master Bug#17678] " jeremyevans0 (Jeremy Evans) via ruby-core
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ivoanjo (Ivo Anjo) via ruby-core @ 2023-08-25 8:12 UTC (permalink / raw)
To: ruby-core; +Cc: ivoanjo (Ivo Anjo)
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 #<Ractor:#2 ractor-test.rb:3 blocking>
[10] Ractor started!
[10] Forking...
[12] In child process, ractor status is #<Ractor:#2 ractor-test.rb:3 blocking>
```
----------------------------------------
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 -- <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]`
```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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:114538] [Ruby master Bug#17678] Ractors do not restart after fork
2021-03-08 16:19 [ruby-core:102776] [Ruby master Bug#17678] Ractors do not restart after fork knuckles
` (2 preceding siblings ...)
2023-08-25 8:12 ` [ruby-core:114528] " ivoanjo (Ivo Anjo) via ruby-core
@ 2023-08-25 14:35 ` jeremyevans0 (Jeremy Evans) via ruby-core
2023-08-25 15:29 ` [ruby-core:114540] " ivoanjo (Ivo Anjo) via ruby-core
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2023-08-25 14:35 UTC (permalink / raw)
To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)
Issue #17678 has been updated by jeremyevans0 (Jeremy Evans).
Tracker changed from Feature to Bug
Backport set to 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
Thanks for that information. It looks like ractors contain information about their state (shown in `inspect`), but that state is not updated on fork, unlike threads. So I think there is a bug, and it's that non-main ractors do not have their state to `terminated` upon fork (forking from non-main ractors is going to be prohibited, see #17516).
----------------------------------------
Bug #17678: Ractors do not restart after fork
https://bugs.ruby-lang.org/issues/17678#change-104340
* Author: ivoanjo (Ivo Anjo)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
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]`
```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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:114540] [Ruby master Bug#17678] Ractors do not restart after fork
2021-03-08 16:19 [ruby-core:102776] [Ruby master Bug#17678] Ractors do not restart after fork knuckles
` (3 preceding siblings ...)
2023-08-25 14:35 ` [ruby-core:114538] [Ruby master Bug#17678] " jeremyevans0 (Jeremy Evans) via ruby-core
@ 2023-08-25 15:29 ` ivoanjo (Ivo Anjo) via ruby-core
2023-08-25 16:29 ` [ruby-core:114543] " jeremyevans0 (Jeremy Evans) via ruby-core
2025-05-08 22:43 ` [ruby-core:121919] [Ruby " jhawthorn (John Hawthorn) via ruby-core
6 siblings, 0 replies; 8+ messages in thread
From: ivoanjo (Ivo Anjo) via ruby-core @ 2023-08-25 15:29 UTC (permalink / raw)
To: ruby-core; +Cc: ivoanjo (Ivo Anjo)
Issue #17678 has been updated by ivoanjo (Ivo Anjo).
Ack, that seems a reasonable way of looking at this, having a way to detect that the ractor is dead would be enough to write some auto-restart code after fork (Erlang supervisor trees here we go :D).
----------------------------------------
Bug #17678: Ractors do not restart after fork
https://bugs.ruby-lang.org/issues/17678#change-104341
* Author: ivoanjo (Ivo Anjo)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
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]`
```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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:114543] [Ruby master Bug#17678] Ractors do not restart after fork
2021-03-08 16:19 [ruby-core:102776] [Ruby master Bug#17678] Ractors do not restart after fork knuckles
` (4 preceding siblings ...)
2023-08-25 15:29 ` [ruby-core:114540] " ivoanjo (Ivo Anjo) via ruby-core
@ 2023-08-25 16:29 ` jeremyevans0 (Jeremy Evans) via ruby-core
2025-05-08 22:43 ` [ruby-core:121919] [Ruby " jhawthorn (John Hawthorn) via ruby-core
6 siblings, 0 replies; 8+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2023-08-25 16:29 UTC (permalink / raw)
To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)
Issue #17678 has been updated by jeremyevans0 (Jeremy Evans).
I updated https://github.com/ruby/ruby/pull/8283 to mark non-main ractors as terminated after fork.
----------------------------------------
Bug #17678: Ractors do not restart after fork
https://bugs.ruby-lang.org/issues/17678#change-104345
* Author: ivoanjo (Ivo Anjo)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
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]`
```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/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:121919] [Ruby Bug#17678] Ractors do not restart after fork
2021-03-08 16:19 [ruby-core:102776] [Ruby master Bug#17678] Ractors do not restart after fork knuckles
` (5 preceding siblings ...)
2023-08-25 16:29 ` [ruby-core:114543] " jeremyevans0 (Jeremy Evans) via ruby-core
@ 2025-05-08 22:43 ` jhawthorn (John Hawthorn) via ruby-core
6 siblings, 0 replies; 8+ messages in thread
From: jhawthorn (John Hawthorn) via ruby-core @ 2025-05-08 22:43 UTC (permalink / raw)
To: ruby-core; +Cc: jhawthorn (John Hawthorn)
Issue #17678 has been updated by jhawthorn (John Hawthorn).
Status changed from Assigned to Closed
Sorry @jeremyevans0 I think Aaron and I missed that PR, but we did the same thing in https://github.com/ruby/ruby/pull/12982 which should fix this.
One thing we didn't do that's in your PR is forbid forking from within a Ractor, but that does seem like a prudent restriction (though it could be limiting for those wanting to fork, make some adjustments, exec)
----------------------------------------
Bug #17678: Ractors do not restart after fork
https://bugs.ruby-lang.org/issues/17678#change-113027
* Author: ivoanjo (Ivo Anjo)
* Status: Closed
* Assignee: ractor
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
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]`
```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/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-05-08 22:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08 16:19 [ruby-core:102776] [Ruby master Bug#17678] Ractors do not restart after fork knuckles
2021-03-09 0:42 ` [ruby-core:102784] " hsbt
2023-08-24 21:12 ` [ruby-core:114513] [Ruby master Feature#17678] " jeremyevans0 (Jeremy Evans) via ruby-core
2023-08-25 8:12 ` [ruby-core:114528] " ivoanjo (Ivo Anjo) via ruby-core
2023-08-25 14:35 ` [ruby-core:114538] [Ruby master Bug#17678] " jeremyevans0 (Jeremy Evans) via ruby-core
2023-08-25 15:29 ` [ruby-core:114540] " ivoanjo (Ivo Anjo) via ruby-core
2023-08-25 16:29 ` [ruby-core:114543] " jeremyevans0 (Jeremy Evans) via ruby-core
2025-05-08 22:43 ` [ruby-core:121919] [Ruby " jhawthorn (John Hawthorn) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).