Fix hClose002 with the threaded RTS IO manager
authorIan Lynagh <ian@well-typed.com>
Sun, 16 Jun 2013 19:16:19 +0000 (20:16 +0100)
committerIan Lynagh <ian@well-typed.com>
Sun, 16 Jun 2013 19:16:19 +0000 (20:16 +0100)
If 'close fd' failed, then the MVars in the callbackTables would be
left empty, which caused deadlocks when we tried to 'take' them again.

Now we use 'finally' to ensure that they are refilled even if 'close'
throws an exception.

GHC/Event/Thread.hs

index cbef3c3..ca8ed1e 100644 (file)
@@ -103,8 +103,7 @@ closeFdWith close fd = do
                       (\mgr table -> M.closeFd_ mgr table fd)
                       mgrs
                       tables
-    close fd
-    zipWithM_ finish mgrs tableAndCbApps
+    close fd `finally` zipWithM_ finish mgrs tableAndCbApps
   where
     finish mgr (table', cbApp) = do
       putMVar (M.callbackTableVar mgr fd) table'