git.iko.soy/distributed-process
on master help sign in
Fix race in runProcess when it fails.

runProcess would yield control back to the caller and then it would try to kill it. This could cause some strange behavior in tests when they fail. Moreover, the former solution assumed exceptions were not masked uninterruptibly. This patch has runProcess work even in such cases.

commitdeadc44f6dff9c4b58cce01986b9927e0e97141e authorFacundo Domínguez <facundo.dominguez@tweag.io> dateSun 25 Oct 2015, 23:23 (11 years ago) parent5bed8d1
1 file changed+5−7
src/Control/Distributed/Process/Node.hs+5−7
src/Control/Distributed/Process/Node.hs+5−7
@@ -205,11 +205,10 @@ import Control.Distributed.Process.Internal.Messaging
205205 )
206206import Control.Distributed.Process.Internal.Primitives
207207 ( register
208− , finally
209208 , receiveWait
210209 , match
211210 , sendChan
212− , catch
211+ , try
213212 , unwrapMessage
214213 )
215214import Control.Distributed.Process.Internal.Types (SendPort, Tracer(..))
@@ -355,11 +354,10 @@ closeLocalNode node = do
355354runProcess :: LocalNode -> Process () -> IO ()
356355runProcess node proc = do
357356 done <- newEmptyMVar
358− tid <- myThreadId
359− void $ forkProcess node $ do
360− catch (proc `finally` liftIO (putMVar done ()))
361− (\(ex :: SomeException) -> liftIO $ throwTo tid ex)
362− takeMVar done
357+ -- TODO; When forkProcess inherits the masking state, protect the forked
358+ -- thread against async exceptions that could occur before 'try' is evaluated.
359+ void $ forkProcess node $ try proc >>= liftIO . putMVar done
360+ takeMVar done >>= either (throwIO :: SomeException -> IO a) return
363361
364362-- | Spawn a new process on a local node
365363forkProcess :: LocalNode -> Process () -> IO ProcessId