Issue #22415 has been updated by nagachika (Tomoyuki Chikanaga). Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: DONE, 4.0: REQUIRED Thank you for creating PRs. Merged into `ruby_3_4` at https://github.com/ruby/ruby/commit/79214e7c6e55aea027312e839b59942ef6163f5a. ---------------------------------------- Bug #22415: Thread.handle_interrupt needs to preserve errinfo https://bugs.ruby-lang.org/issues/22415#change-119558 * Author: rwstauner (Randy Stauner) * Status: Closed * Backport: 3.3: REQUIRED, 3.4: DONE, 4.0: REQUIRED ---------------------------------------- Thread.handle_interrupt checks for interrupts after its block has returned but before re-raising the break/return that left the block. A signal trap that runs in that window clears ec->errinfo, which is where the throw data for the pending break/return lives, so the VM throws nil. This small script reproduces the SEGV very quickly: ```ruby trap(:USR1) { raise "boom" rescue nil } pid = $$ killer = fork { (Process.kill(:USR1, pid); sleep 0.001) while Process.ppid == pid } 1_000_000.times { Thread.handle_interrupt(Exception => :immediate) { break } } Process.kill(:KILL, killer) puts "no crash" ``` -- https://bugs.ruby-lang.org/