[GHC] #8433: forkProcess masks async exceptions inside the child process
#8433: forkProcess masks async exceptions inside the child process ------------------------------------+--------------------------------- Reporter: joeyh | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/unix | Version: 7.6.3 Keywords: | Operating System: Linux Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+--------------------------------- Frankly, I'm not sure if this is a bug, but the forkProcess documentation says nothing about it. This can lead to problems when writing a multi- threaded daemon that expects async exceptions to work as they usually would. FWIW, I have looked at several of the libraries on hackage that handle daemonization, and none of them seem to deal with this by explicitly unmasking exceptions when running the daemon IO action. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8433> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8433: forkProcess masks async exceptions inside the child process -----------------------------------+------------------------------------ Reporter: joeyh | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/unix | Version: 7.6.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -----------------------------------+------------------------------------ Comment (by hvr): Here's a simple way to reproduce: {{{#!hs System.Posix.Process.forkProcess $ print =<< Control.Exception.getMaskingState }}} outputs `MaskedInterrupt` with GHC 7.6.3 on Linux -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8433#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8433: forkProcess masks async exceptions inside the child process -----------------------------------+------------------------------------ Reporter: joeyh | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/unix | Version: 7.6.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -----------------------------------+------------------------------------ Comment (by hvr): Potential fix: {{{#!hs forkProcess :: IO () -> IO ProcessID forkProcess action = do -- wrap action to re-establish caller's masking state, as -- 'forkProcessPrim' starts in 'MaskedInterruptible' state by -- default; see also #1048 mstate <- getMaskingState let action' = case mstate of Unmasked -> unsafeUnmask action MaskedInterruptible -> action MaskedUninterruptible -> uninterruptibleMask_ action bracket (newStablePtr (runIO action')) freeStablePtr (\stable -> throwErrnoIfMinus1 "forkProcess" (forkProcessPrim stable)) }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8433#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8433: forkProcess masks async exceptions inside the child process -----------------------------------+------------------------------------ Reporter: joeyh | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/unix | Version: 7.6.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -----------------------------------+------------------------------------ Comment (by Herbert Valerio Riedel <hvr@…>): In [changeset:"897d66ad9d77d17dae1b5ac94af792e671a76c13/unix"]: {{{ #!CommitTicketReference repository="unix" revision="897d66ad9d77d17dae1b5ac94af792e671a76c13" Fix `forkProcess` to inherit caller's `MaskingState` ...and while at it, use `bracket` to fix a potential resource leak due to `freeStablePtr` not being called if `throwErrnoIfMinus1` throws an exception. This fixes #8433 Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org> }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8433#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8433: forkProcess masks async exceptions inside the child process -----------------------------------+------------------------------------ Reporter: joeyh | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/unix | Version: 7.6.3 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -----------------------------------+------------------------------------ Comment (by Herbert Valerio Riedel <hvr@…>): In [changeset:"17192d89e642c463a1987fa3cc5cca2eb546bec7/unix"]: {{{ #!CommitTicketReference repository="unix" revision="17192d89e642c463a1987fa3cc5cca2eb546bec7" Add `forkProcessWithUnmask` function This seemed to be an obvious addition while working on #8433. Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org> }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8433#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8433: forkProcess masks async exceptions inside the child process ------------------------------------------------+-------------------------- Reporter: joeyh | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.8.1 Component: libraries/unix | Version: 7.6.3 Resolution: fixed | Keywords: Operating System: Linux | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by hvr): * status: new => closed * failure: None/Unknown => Incorrect result at runtime * resolution: => fixed * milestone: => 7.8.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8433#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC