From 8c7dfc93b523957334c3b93530a85b7dcfa5cfb1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 15 Jun 2012 18:31:18 -0400 Subject: [PATCH] catch IO exceptions in runThreadState A few places catch IO errors after calling runThreadState, but since the MVar was not restored, it'd later deadlock trying to read from it. I'd like to catch all exceptions here, but I could not get the types to unify. --- Assistant/ThreadedMonad.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Assistant/ThreadedMonad.hs b/Assistant/ThreadedMonad.hs index c4d331f61b..51f579d07f 100644 --- a/Assistant/ThreadedMonad.hs +++ b/Assistant/ThreadedMonad.hs @@ -11,6 +11,7 @@ import Common.Annex import qualified Annex import Control.Concurrent +import Control.Exception (throw) {- The Annex state is stored in a MVar, so that threaded actions can access - it. -} @@ -35,6 +36,9 @@ withThreadState a = do runThreadState :: ThreadState -> Annex a -> IO a runThreadState mvar a = do startstate <- takeMVar mvar - !(r, newstate) <- Annex.run startstate a + -- catch IO errors and rethrow after restoring the MVar + !(r, newstate) <- catchIO (Annex.run startstate a) $ \e -> do + putMVar mvar startstate + throw e putMVar mvar newstate return r