[GHC] #10017: signal handlers are invoked multiple times when the threaded rts is used

#10017: signal handlers are invoked multiple times when the threaded rts is used -------------------------------------+------------------------------------- Reporter: redneb | Owner: simonmar Type: bug | Status: new Priority: normal | Milestone: Component: Runtime | Version: 7.10.1-rc1 System | Operating System: Linux Keywords: | Type of failure: Incorrect result Architecture: | at runtime Unknown/Multiple | Blocked By: Test Case: | Related Tickets: #9423 Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- 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: {{{#!hs 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 f9f89b7884ccc8ee5047cf4fffdf2b36df6832df (which was later [changeset:4748f5936fe72d96edfa17b153dbfd84f2c4c053 reverted] but then [changeset:7e658bc14e2dd6baf208deebbdab9e1285ce4c72 re- added]), a commit addressing #9423. The cause of the problem is [source:/rts/posix/Signals.c@f44bbc83bab62f9a2d25e69d87c2b4af25318d52#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@f44bbc83bab62f9a2d25e69d87c2b4af25318d52#L183 here])? Removing the loop seems to solve the issue, but I don't know if it makes #9423 reappear. I cannot test this on a Mac OS X right now. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10017 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10017: signal handlers are invoked multiple times when the threaded rts is used -------------------------------------+------------------------------------- Reporter: redneb | Owner: simonmar Type: bug | Status: new Priority: highest | Milestone: 7.10.1 Component: Runtime System | Version: 7.10.1-rc1 Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9423 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by simonmar): * cc: thoughtpolice (added) * priority: normal => highest * milestone: => 7.10.1 Comment: Yikes. Austin: this looks like a release blocker. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10017#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10017: signal handlers are invoked multiple times when the threaded rts is used -------------------------------------+------------------------------------- Reporter: redneb | Owner: simonmar Type: bug | Status: new Priority: highest | Milestone: 7.10.1 Component: Runtime System | Version: 7.10.1-rc1 Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9423 | Differential Revisions: -------------------------------------+------------------------------------- Comment (by AndreasVoellmy): I'm still getting up to speed, but it looks like that offending loop in `generic_handler` should just be removed. We have to signal to all the control pipes in `ioManagerDie()` (to solve the issue that led to that commit), but not in `generic_handler` (it seems). I'll look into it a bit more to check my understand and run some tests. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10017#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10017: signal handlers are invoked multiple times when the threaded rts is used -------------------------------------+------------------------------------- Reporter: redneb | Owner: Type: bug | AndreasVoellmy Priority: highest | Status: new Component: Runtime System | Milestone: 7.10.1 Resolution: | Version: 7.10.1-rc1 Operating System: Linux | Keywords: Type of failure: Incorrect result | Architecture: at runtime | Unknown/Multiple Blocked By: | Test Case: Related Tickets: #9423 | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by AndreasVoellmy): * owner: simonmar => AndreasVoellmy -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10017#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10017: signal handlers are invoked multiple times when the threaded rts is used -------------------------------------+------------------------------------- Reporter: redneb | Owner: Type: bug | AndreasVoellmy Priority: highest | Status: new Component: Runtime System | Milestone: 7.10.1 Resolution: | Version: 7.10.1-rc1 Operating System: Linux | Keywords: Type of failure: Incorrect result | Architecture: at runtime | Unknown/Multiple Blocked By: | Test Case: Related Tickets: #9423 | Blocking: | Differential Revisions: Phab:D641 -------------------------------------+------------------------------------- Changes (by AndreasVoellmy): * differential: => Phab:D641 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10017#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10017: signal handlers are invoked multiple times when the threaded rts is used -------------------------------------+------------------------------------- Reporter: redneb | Owner: Type: bug | AndreasVoellmy Priority: highest | Status: new Component: Runtime System | Milestone: 7.10.1 Resolution: | Version: 7.10.1-rc1 Operating System: Linux | Keywords: Type of failure: Incorrect result | Architecture: at runtime | Unknown/Multiple Blocked By: | Test Case: Related Tickets: #9423 | Blocking: | Differential Revisions: Phab:D641 -------------------------------------+------------------------------------- Comment (by AndreasVoellmy): In the threaded RTS, a signal is delivered from the RTS to Haskell user code by writing to file that one of the IO managers watches (via an instance of GHC.Event.Control.Control). When the IO manager receives the signal, it calls GHC.Conc.Signal.runHandlers to invoke Haskell signal handler. In the move from a single IO manager to one IO manager per capability, the behavior was (wrongly) extended so that a signal is delivered to every event manager (see Trac #9423), each of which invoke Haskell signal handlers, leading to multiple invocations of Haskell signal handlers for a single signal. This change fixes this problem by having the RTS (in generic_handler()) notify only the Control instance used by the TimerManager, rather than all the per-capability IO managers. This has no impact on #9423; i.e. the fix here does not re-introduce the issue identified in #9423. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10017#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10017: signal handlers are invoked multiple times when the threaded rts is used
-------------------------------------+-------------------------------------
Reporter: redneb | Owner:
Type: bug | AndreasVoellmy
Priority: highest | Status: new
Component: Runtime System | Milestone: 7.10.1
Resolution: | Version: 7.10.1-rc1
Operating System: Linux | Keywords:
Type of failure: Incorrect result | Architecture:
at runtime | Unknown/Multiple
Blocked By: | Test Case:
Related Tickets: #9423 | Blocking:
| Differential Revisions: Phab:D641
-------------------------------------+-------------------------------------
Comment (by Andreas Voellmy

#10017: signal handlers are invoked multiple times when the threaded rts is used -------------------------------------+------------------------------------- Reporter: redneb | Owner: Type: bug | AndreasVoellmy Priority: highest | Status: merge Component: Runtime System | Milestone: 7.10.1 Resolution: | Version: 7.10.1-rc1 Operating System: Linux | Keywords: Type of failure: Incorrect result | Architecture: at runtime | Unknown/Multiple Blocked By: | Test Case: Related Tickets: #9423 | Blocking: | Differential Revisions: Phab:D641 -------------------------------------+------------------------------------- Changes (by AndreasVoellmy): * status: new => merge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10017#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10017: signal handlers are invoked multiple times when the threaded rts is used -------------------------------------+------------------------------------- Reporter: redneb | Owner: Type: bug | AndreasVoellmy Priority: highest | Status: closed Component: Runtime System | Milestone: 7.10.1 Resolution: fixed | Version: 7.10.1-rc1 Operating System: Linux | Keywords: Type of failure: Incorrect result | Architecture: at runtime | Unknown/Multiple Blocked By: | Test Case: Related Tickets: #9423 | Blocking: | Differential Revisions: Phab:D641 -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: merge => closed * resolution: => fixed Comment: Boom, headshot. Merged to `ghc-7.10` via ddd95c0b575da33447c078a8791d3c4f2edec9b7. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10017#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10017: signal handlers are invoked multiple times when the threaded rts is used
-------------------------------------+-------------------------------------
Reporter: redneb | Owner:
Type: bug | AndreasVoellmy
Priority: highest | Status: closed
Component: Runtime System | Milestone: 7.10.1
Resolution: fixed | Version: 7.10.1-rc1
Operating System: Linux | Keywords:
Type of failure: Incorrect result | Architecture:
at runtime | Unknown/Multiple
Blocked By: | Test Case:
Related Tickets: #9423 | Blocking:
| Differential Revisions: Phab:D641
-------------------------------------+-------------------------------------
Comment (by Simon Marlow
participants (1)
-
GHC