* [ruby-core:119559] [Ruby master Feature#20805] Allow Ractor#send from a signal trap Proc
@ 2024-10-21 8:50 kirs (Kir Shatrov) via ruby-core
2024-10-25 14:41 ` [ruby-core:119620] " alanwu (Alan Wu) via ruby-core
0 siblings, 1 reply; 2+ messages in thread
From: kirs (Kir Shatrov) via ruby-core @ 2024-10-21 8:50 UTC (permalink / raw)
To: ruby-core; +Cc: kirs (Kir Shatrov)
Issue #20805 has been reported by kirs (Kir Shatrov).
----------------------------------------
Feature #20805: Allow Ractor#send from a signal trap Proc
https://bugs.ruby-lang.org/issues/20805
* Author: kirs (Kir Shatrov)
* Status: Open
----------------------------------------
It was surfaced in https://bugs.ruby-lang.org/issues/18139 that Ractor is designed to "unexpected interruption free" and it's not supposed to have a `kill`-like method.
A better alternative to that would be allow the main Ractor to consume a shutdown signal from the pipe.
Example:
```ruby
shutdown_ractor = Ractor.new do
Ractor.recv # Wait for a signal
end
# Signal trap for SIGTERM
Signal.trap("TERM") do
puts "Received SIGTERM, shutting down..."
shutdown_ractor.send(:shutdown) # Send the shutdown signal
end
pipe = Ractor.new do
loop do
r, value = Ractor.select(Ractor.recv, shutdown_ractor)
if r == shutdown_ractor # Shutdown signal received
break
else
Ractor.yield(value, move: true) # Normal operation
end
end
end
```
However, it's not possible to do `Ractor#send` from a trap Proc right now:
```
<internal:ractor>:282:in `new': can not isolate a Proc because it accesses outer variables (shutdown_ractor). (ArgumentError)
```
>From what I've gathered, it makes it impossible to implement any graceful shutdown in a process with a few Ractors running.
--
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] 2+ messages in thread
* [ruby-core:119620] [Ruby master Feature#20805] Allow Ractor#send from a signal trap Proc
2024-10-21 8:50 [ruby-core:119559] [Ruby master Feature#20805] Allow Ractor#send from a signal trap Proc kirs (Kir Shatrov) via ruby-core
@ 2024-10-25 14:41 ` alanwu (Alan Wu) via ruby-core
0 siblings, 0 replies; 2+ messages in thread
From: alanwu (Alan Wu) via ruby-core @ 2024-10-25 14:41 UTC (permalink / raw)
To: ruby-core; +Cc: alanwu (Alan Wu)
Issue #20805 has been updated by alanwu (Alan Wu).
It works if you make `shutdown_ractor` a constant:
```ruby
p Process.pid
SHUTDOWN_RACTOR = Ractor.new do
Ractor.recv # Wait for a signal
puts "goodbye"
exit!
end
# Signal trap for SIGTERM
Signal.trap("TERM") do
puts "Received SIGTERM, shutting down..."
SHUTDOWN_RACTOR.send(:shutdown) # Send the shutdown signal
end
sleep
```
```shell
ruby -v test.rb
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin24]
79270
test.rb:3: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
Received SIGTERM, shutting down...
goodbye
```
Not to minimize the usability issue you experienced.
----------------------------------------
Feature #20805: Allow Ractor#send from a signal trap Proc
https://bugs.ruby-lang.org/issues/20805#change-110242
* Author: kirs (Kir Shatrov)
* Status: Open
----------------------------------------
It was surfaced in https://bugs.ruby-lang.org/issues/18139 that Ractor is designed to "unexpected interruption free" and it's not supposed to have a `kill`-like method.
A better alternative to that would be allow the main Ractor to consume a shutdown signal from the pipe.
Example:
```ruby
shutdown_ractor = Ractor.new do
Ractor.recv # Wait for a signal
end
# Signal trap for SIGTERM
Signal.trap("TERM") do
puts "Received SIGTERM, shutting down..."
shutdown_ractor.send(:shutdown) # Send the shutdown signal
end
pipe = Ractor.new do
loop do
r, value = Ractor.select(Ractor.recv, shutdown_ractor)
if r == shutdown_ractor # Shutdown signal received
break
else
Ractor.yield(value, move: true) # Normal operation
end
end
end
```
However, it's not possible to do `Ractor#send` from a trap Proc right now:
```
<internal:ractor>:282:in `new': can not isolate a Proc because it accesses outer variables (shutdown_ractor). (ArgumentError)
```
>From what I've gathered, it makes it impossible to implement any graceful shutdown in a process with a few Ractors running.
--
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] 2+ messages in thread
end of thread, other threads:[~2024-10-25 14:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-21 8:50 [ruby-core:119559] [Ruby master Feature#20805] Allow Ractor#send from a signal trap Proc kirs (Kir Shatrov) via ruby-core
2024-10-25 14:41 ` [ruby-core:119620] " alanwu (Alan Wu) 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).