Skip to content

signal handlers are invoked multiple times when the threaded rts is used

When you install a custom signal handler and the threaded rts is being used, then the signal handler will be invoked multiple times. Here's a program that the demonstrates this:

import Control.Concurrent
import System.Posix.Signals

main :: IO ()
main = do
    _ <- flip (installHandler sig) Nothing $ Catch $
        putStrLn $ "Received signal " ++ show sig
    raiseSignal sig
    threadDelay 100000
  where
    sig = sigUSR2

If you compile this with the -threaded flag and then run it with say +RTS -N4 then it produces the following output:

Received signal 12
Received signal 12
Received signal 12
Received signal 12
Received signal 12

In general the signal handler is invoked n_capabilities+1 times. This also happens with all other signals.

This regression was introduced by f9f89b78 (which was later [changeset:4748f593 reverted] but then [changeset:7e658bc1 re-added]), a commit addressing #9423 (closed).

The cause of the problem is [source:/rts/posix/Signals.c@f44bbc83#L256 this] loop. I don't understand why we need to write an event about the signal received in the per capability control pipe introduced by the aforementioned commit. Aren't these control pipes supposed only to be used to shutdown the capabilities (which happens [source:/rts/posix/Signals.c@f44bbc83#L183 here])?

Removing the loop seems to solve the issue, but I don't know if it makes #9423 (closed) reappear. I cannot test this on a Mac OS X right now.

Trac metadata
Trac field Value
Version 7.10.1-rc1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Runtime System
Test case
Differential revisions
BlockedBy
Related
Blocking
CC AndreasVoellmy, simonmar
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information