Skip to content

Commit 2233ea3

Browse files
Restore fork child interrupt traps.
Assisted-By: devx/3236e566-7538-432e-a30a-2bdf37265ed4
1 parent fc315cb commit 2233ea3

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

lib/async/container/forked.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ def self.fork(**options)
104104
# Fork from `Thread.new` so the child does not inherit the parent fiber scheduler or the current caller's fiber stack. Only this short-lived thread is copied into the child process:
105105
::Thread.new do
106106
::Process.fork do
107+
# Convert process signals into pending interrupts on the surviving fork thread so they respect `Thread.handle_interrupt` in the child:
108+
::Signal.trap(:INT){::Thread.current.raise(::Interrupt)}
109+
::Signal.trap(:TERM){::Thread.current.raise(::Interrupt)}
110+
107111
# Reset interrupt masking - `Exception` is a fast path:
108112
::Thread.handle_interrupt(Exception => :immediate) do
109113
yield Instance.for(process)

0 commit comments

Comments
 (0)