#4533: IO manager can leak MVars if threads are killed
---------------------------------+------------------------------------------
Reporter: bos | Owner: bos
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Runtime System | Version: 7.0.1
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: Incorrect result at runtime
---------------------------------+------------------------------------------
Comment(by simonmar):
We need to think about the consequences of changing the base API and
whether we can do this in a minor release. Normally we don't make API
changes, but if the API change is just an addition and is necessary to fix
a bug, then a case could be made.
Quick patch review. Instead of this:
{{{
takeMVar m `catch` \(e::SomeException) ->
M.unregisterTimeout mgr reg >> throw e
}}}
it's better to write
{{{
takeMVar m `onException` M.unregisterTimeout mgr reg
}}}
However, I'm a little concerned that you haven't closed the leak fully
here. I think you want a `mask_`:
{{{
threadDelay :: Int -> IO ()
threadDelay usecs = mask_ $ do
Just mgr <- readIORef eventManager
m <- newEmptyMVar
_ <- registerTimeout mgr usecs (putMVar m ())
takeMVar m `onException` M.unregisterTimeout mgr reg
}}}
otherwise an exception could strike after `registerTimeout` but before
`takeMVar`. Perhaps it works without the `mask_`, but that would only be
by accident.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4533#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs