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.
This commit is contained in:
Joey Hess 2012-06-15 18:31:18 -04:00
parent 53d2e81ffd
commit 8c7dfc93b5

View file

@ -11,6 +11,7 @@ import Common.Annex
import qualified Annex import qualified Annex
import Control.Concurrent import Control.Concurrent
import Control.Exception (throw)
{- The Annex state is stored in a MVar, so that threaded actions can access {- The Annex state is stored in a MVar, so that threaded actions can access
- it. -} - it. -}
@ -35,6 +36,9 @@ withThreadState a = do
runThreadState :: ThreadState -> Annex a -> IO a runThreadState :: ThreadState -> Annex a -> IO a
runThreadState mvar a = do runThreadState mvar a = do
startstate <- takeMVar mvar 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 putMVar mvar newstate
return r return r