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.

commit01ec001ddc4566919605f0eed56bbb42b21b4b95 authorFacundo Domínguez <facundo.dominguez@tweag.io> dateWed 20 Apr 2016, 08:27 (10 years ago) parent5eaedc2
1 file changed+5−4
src/Control/Distributed/Process/Node.hs+5−4
src/Control/Distributed/Process/Node.hs+5−4
@@ -1172,16 +1172,17 @@ throwException :: Exception e => ProcessId -> e -> NC ()
11721172throwException pid e = do
11731173 node <- ask
11741174 -- throwTo blocks until the exception is received by the target thread.
1175− -- We fork a helper thread to avoid blocking the node controller.
1176− liftIO $ withLocalProc node pid $ \p -> void $ forkIO $ throwTo (processThread p) e
1175+ -- We cannot easily make it happen asynchronpusly because then 'unlink'
1176+ -- semantics would break.
1177+ liftIO $ withLocalProc node pid $ \p -> throwTo (processThread p) e
11771178
11781179withLocalProc :: LocalNode -> ProcessId -> (LocalProcess -> IO ()) -> IO ()
11791180withLocalProc node pid p =
11801181 -- By [Unified: table 6, rule missing_process] messages to dead processes
11811182 -- can silently be dropped
11821183 let lpid = processLocalId pid in do
1183− withValidLocalState node $ \vst ->
1184− forM_ (vst ^. localProcessWithId lpid) p
1184+ join $ withValidLocalState node $ \vst ->
1185+ return $ forM_ (vst ^. localProcessWithId lpid) p
11851186
11861187--------------------------------------------------------------------------------
11871188-- Accessors --