
#13891: forkIO can trivially defeat bracket -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Consider this program, {{{#!hs import Control.Concurrent import Control.Exception main = do putStrLn "forking" forkIO $ bracket (putStrLn "forked") (const $ putStrLn "finalize") (const $ putStrLn "hello" >> threadDelay 100000000) threadDelay 10000 putStrLn "done" }}} Would you predict that it would print `finalize`? Answer: no. It will print, {{{ forking forked hello done }}} It would pointed out by an author of a cryptographic library (`raaz`) that this is quite bad as it means that secure memory could leak out uncleared. It's not entirely clear how best to deal with this. Perhaps raise a `ThreadKilled` async exception to all running threads during RTS shutdown, followed by a synchronization? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13891 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler