git.iko.soy/distributed-process
on master help sign in
Don't throw exceptions asynchronously.

This undoes the fix in 07dbb9b3 since it breaks unlink semantics. With exceptions sent asynchronously, a ProcessLinkException could be delivered to a process after it has unlinked. To avoid introducing a deadlock when forkProcess cleans up, we release the node state MVar before calling throwTo.

commitd0e362e31f41045125bce12329aa513e3784a53d authorFacundo Domínguez <facundo.dominguez@tweag.io> dateWed 20 Apr 2016, 08:27 (11 years ago) parenta171a89
1 file changed+5−4
src/Control/Distributed/Process/Node.hs+5−4
src/Control/Distributed/Process/Node.hs+5−4
@@ -1166,16 +1166,17 @@ throwException :: Exception e => ProcessId -> e -> NC ()
11661166throwException pid e = do
11671167 node <- ask
11681168 -- throwTo blocks until the exception is received by the target thread.
1169− -- We fork a helper thread to avoid blocking the node controller.
1170− liftIO $ withLocalProc node pid $ \p -> void $ forkIO $ throwTo (processThread p) e
1169+ -- We cannot easily make it happen asynchronpusly because then 'unlink'
1170+ -- semantics would break.
1171+ liftIO $ withLocalProc node pid $ \p -> throwTo (processThread p) e
11711172
11721173withLocalProc :: LocalNode -> ProcessId -> (LocalProcess -> IO ()) -> IO ()
11731174withLocalProc node pid p =
11741175 -- By [Unified: table 6, rule missing_process] messages to dead processes
11751176 -- can silently be dropped
11761177 let lpid = processLocalId pid in do
1177− withValidLocalState node $ \vst ->
1178− forM_ (vst ^. localProcessWithId lpid) p
1178+ join $ withValidLocalState node $ \vst ->
1179+ return $ forM_ (vst ^. localProcessWithId lpid) p
11791180
11801181--------------------------------------------------------------------------------
11811182-- Accessors --