Project

General

Profile

Actions

Bug #4909

closed

trapハンドラは再入されてはいけないのではないか?

Added by kosaki (Motohiro KOSAKI) almost 13 years ago. Updated over 11 years ago.

Status:
Closed
Target version:
ruby -v:
-
Backport:
[ruby-dev:43852]

Description

以下のプログラムは

if intrap == 1
raise "trap nested"
end

が真になってしまって例外終了してしまうのですが、これは起きてはいけないのではないでしょうか。
以下の二点が問題だと考えます。

1)このプログラムのようにシグナルを連続して配送されるとスタックオーバーフローを引き起こせる
2)Rubyレベルでsigprocmask()に相当するシグナルブロッキング操作が提供されていないため、
正しいトラップハンドラを書くのが、ほぼ不可能になっている

C言語ですら、シグナルハンドラ実行中はシグナルが自動的にマスクされるんですから、Rubyでも
同レベルの配慮はMRIがおこなうべきだと思います。


n = 0
intrap = 0

parent = $$

trap(:USR1) {
if intrap == 1
raise "trap nested"
end
intrap = 1
10000.times {
n += 1
}
intrap = 0
}

fork do
Process.kill(:USR1, parent) while true
end

sleep 100


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #6009: Rapid signal delivery via kill(2) causes SystemStackErrorClosedkosaki (Motohiro KOSAKI)02/13/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0