[GHC] #9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit()
#9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit() -------------------------------------+------------------------------------- Reporter: AndreasVoellmy | Owner: simonmar Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.8.2 Keywords: | Operating System: MacOS X Architecture: Unknown/Multiple | Type of failure: Incorrect Difficulty: Unknown | result at runtime Blocked By: | Test Case: Related Tickets: 9284 | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Issue #9284 relates to `forkProcess`, which previously invoked the same code that is invoked by `hs_exit` and uncovered this problem. The resolution of #9284 is to not invoke the equivalent of `hs_exit` (for reasons that you can see in #9284). However, `hs_exit` can be called by programs that explicitly create and teardown a Haskell runtime, so the problem displayed by #9284 can still occur for those programs. The problem has only been observed on OS X, though it probably could occur on Linux OSes as well. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9423> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit() -------------------------------------+------------------------------------- Reporter: | Owner: simonmar AndreasVoellmy | Status: new Type: bug | Milestone: Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: MacOS X | Blocked By: Type of failure: Incorrect | Related Tickets: 9284 result at runtime | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by AndreasVoellmy): The attached program illustrates the problem. Compile like this, where `<your-ghc>` should be a recent (7.8.x) GHC: {{{ <your-ghc> -c Foo.hs <your-ghc> -threaded -no-hs-main FooMain.c Foo.o }}} Then run `a.out`. You should see some printouts and then it should hang (i.e. fail to terminate). You may need to run it a few times t see the behavior. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9423#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit() -------------------------------------+------------------------------------- Reporter: | Owner: simonmar AndreasVoellmy | Status: new Type: bug | Milestone: Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: MacOS X | Blocked By: Type of failure: Incorrect | Related Tickets: 9284 result at runtime | Test Case: | Blocking: | Differential Revisions: Phab:D129 | -------------------------------------+------------------------------------- Changes (by AndreasVoellmy): * differential: => Phab:D129 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9423#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit() -------------------------------------+------------------------------------- Reporter: | Owner: simonmar AndreasVoellmy | Status: new Type: bug | Milestone: Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: MacOS X | Blocked By: Type of failure: Incorrect | Related Tickets: 9284 result at runtime | Test Case: | Blocking: | Differential Revisions: Phab:D129 | -------------------------------------+------------------------------------- Comment (by Austin Seipp <austin@…>): In [changeset:"f9f89b7884ccc8ee5047cf4fffdf2b36df6832df/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="f9f89b7884ccc8ee5047cf4fffdf2b36df6832df" rts/base: Fix #9423 Summary: Fix #9423. The problem in #9423 is caused when code invoked by `hs_exit()` waits on all foreign calls to return, but some IO managers are in `safe` foreign calls and do not return. The previous design signaled to the timer manager (via its control pipe) that it should "die" and when the timer manager returned to Haskell-land, the Haskell code in timer manager then signalled to the IO manager threads that they should return from foreign calls and `die`. Unfortunately, in the shutdown sequence the timer manager is unable to return to Haskell-land fast enough and so the code that signals to the IO manager threads (via their control pipes) is never executed and the IO manager threads remain out in the foreign calls. This patch solves this problem by having the RTS signal to all the IO manager threads (via their control pipes; and in addition to signalling to the timer manager thread) that they should shutdown (in `ioManagerDie()` in `rts/Signals.c`. To do this, we arrange for each IO manager thread to register its control pipe with the RTS (in `GHC.Thread.startIOManagerThread`). In addition, `GHC.Thread.startTimerManagerThread` registers its control pipe. These are registered via C functions `setTimerManagerControlFd` (in `rts/Signals.c`) and `setIOManagerControlFd` (in `rts/Capability.c`). The IO manager control pipe file descriptors are stored in a new field of the `Capability_ struct`. Test Plan: See the notes on #9423 to recreate the problem and to verify that it no longer occurs with the fix. Auditors: simonmar Reviewers: simonmar, edsko, ezyang, austin Reviewed By: austin Subscribers: phaskell, simonmar, ezyang, carter, relrod Differential Revision: https://phabricator.haskell.org/D129 GHC Trac Issues: #9423, #9284 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9423#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit() -------------------------------------+------------------------------------- Reporter: | Owner: simonmar AndreasVoellmy | Status: closed Type: bug | Milestone: 7.10.1 Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: fixed | Difficulty: Unknown Operating System: MacOS X | Blocked By: Type of failure: Incorrect | Related Tickets: 9284 result at runtime | Test Case: | Blocking: | Differential Revisions: Phab:D129 | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: new => closed * resolution: => fixed * milestone: => 7.10.1 Comment: Merged, thanks Andreas! -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9423#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit() -------------------------------------+------------------------------------- Reporter: | Owner: simonmar AndreasVoellmy | Status: closed Type: bug | Milestone: 7.10.1 Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: fixed | Difficulty: Unknown Operating System: MacOS X | Blocked By: Type of failure: Incorrect | Related Tickets: 9284 result at runtime | Test Case: | Blocking: | Differential Revisions: Phab:D129 | -------------------------------------+------------------------------------- Comment (by Austin Seipp <austin@…>): In [changeset:"4748f5936fe72d96edfa17b153dbfd84f2c4c053/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="4748f5936fe72d96edfa17b153dbfd84f2c4c053" Revert "rts/base: Fix #9423" This should fix the Windows fallout, and hopefully this will be fixed once that's sorted out. This reverts commit f9f89b7884ccc8ee5047cf4fffdf2b36df6832df. Signed-off-by: Austin Seipp <austin@well-typed.com> }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9423#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit() -------------------------------------+------------------------------------- Reporter: | Owner: AndreasVoellmy | Status: new Type: bug | Milestone: 7.10.1 Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: MacOS X | Blocked By: Type of failure: Incorrect | Related Tickets: 9284 result at runtime | Test Case: | Blocking: | Differential Revisions: Phab:D129 | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * owner: simonmar => * status: closed => new * resolution: fixed => -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9423#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit() -------------------------------------+------------------------------------- Reporter: | Owner: AndreasVoellmy | Status: new Type: bug | Milestone: 7.10.1 Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: MacOS X | Blocked By: Type of failure: Incorrect | Related Tickets: 9284 result at runtime | Test Case: | Blocking: | Differential Revisions: Phab:D129 | -------------------------------------+------------------------------------- Comment (by AndreasVoellmy): Are there ticket numbers for the "Windows fallout" stuff? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9423#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit() -------------------------------------+------------------------------------- Reporter: | Owner: AndreasVoellmy | Status: new Type: bug | Milestone: 7.10.1 Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: MacOS X | Blocked By: Type of failure: Incorrect | Related Tickets: 9284 result at runtime | Test Case: | Blocking: | Differential Revisions: Phab:D129 | -------------------------------------+------------------------------------- Comment (by Austin Seipp <austin@…>): In [changeset:"7e658bc14e2dd6baf208deebbdab9e1285ce4c72/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="7e658bc14e2dd6baf208deebbdab9e1285ce4c72" Revert "Revert "rts/base: Fix #9423"" and resolve issue that caused the revert. Summary: This reverts commit 4748f5936fe72d96edfa17b153dbfd84f2c4c053. The fix for #9423 was reverted because this commit introduced a C function setIOManagerControlFd() (defined in Schedule.c) defined for all OS types, while the prototype (in includes/rts/IOManager.h) was only included when mingw32_HOST_OS is not defined. This broke Windows builds. This commit reverts the original commit and resolves the problem by only defining setIOManagerControlFd() when mingw32_HOST_OS is defined. Hence the missing prototype error should not occur on Windows. In addition, since the io_manager_control_wr_fd field of the Capability struct is only usd by the setIOManagerControlFd, this commit includes the io_manager_control_wr_fd field in the Capability struct only when mingw32_HOST_OS is not defined. Test Plan: Try to compile successfully on all platforms. Reviewers: austin Reviewed By: austin Subscribers: simonmar, ezyang, carter Differential Revision: https://phabricator.haskell.org/D174 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9423#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit() -------------------------------------+------------------------------------- Reporter: | Owner: AndreasVoellmy | Status: closed Type: bug | Milestone: 7.10.1 Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: fixed | Difficulty: Unknown Operating System: MacOS X | Blocked By: Type of failure: Incorrect | Related Tickets: 9284 result at runtime | Test Case: | Blocking: | Differential Revisions: Phab:D129 | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: new => closed * resolution: => fixed Comment: OK, this should be fixed For Real this time. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9423#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9423: shutdownCapability sometimes loops indefinitely on OSX after hs_exit() -------------------------------------+------------------------------------- Reporter: AndreasVoellmy | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Runtime System | Version: 7.8.2 Resolution: fixed | Keywords: Operating System: MacOS X | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: 9284 | Differential Revisions: Phab:D129 -------------------------------------+------------------------------------- Comment (by Andreas Voellmy <andreas.voellmy@…>): In [changeset:"92c93544939199f6ef758e1658149a971d4437c9/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="92c93544939199f6ef758e1658149a971d4437c9" Fix #10017 Summary: 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 #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. Reviewers: austin, hvr, simonmar, Mikolaj Reviewed By: simonmar, Mikolaj Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D641 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9423#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC