git.iko.soy/distributed-process
on master help sign in
Fix monitor race in 'call' (DP-103).
commit6ca74eaf145963e5195c6c0601e67ca0d6bf575b authorFacundo Domínguez <facundo.dominguez@tweag.io> dateTue 24 Feb 2015, 09:20 (12 years ago) parent4d3472a
1 file changed+9−5
src/Control/Distributed/Process/Internal/Spawn.hs+9−5
src/Control/Distributed/Process/Internal/Spawn.hs+9−5
@@ -38,6 +38,8 @@ import Control.Distributed.Process.Internal.Closure.BuiltIn
3838 , cpSend
3939 , cpNewChan
4040 , cpDelayed
41+ , returnCP
42+ , sdictUnit
4143 )
4244import Control.Distributed.Process.Internal.Primitives
4345 ( -- Basic messaging
@@ -109,12 +111,14 @@ call :: Serializable a
109111 -> Process a
110112call dict nid proc = do
111113 us <- getSelfPid
112− (pid, mRef) <- spawnMonitor nid (proc `bindCP` cpSend dict us)
113− -- We are guaranteed to receive the reply before the monitor notification
114− -- (if a reply is sent at all)
115− -- NOTE: This might not be true if we switch to unreliable delivery.
114+ (pid, mRef) <- spawnMonitor nid (proc `bindCP`
115+ cpSend dict us `seqCP`
116+ -- Delay so the process does not terminate
117+ -- before the response arrives.
118+ cpDelayed us (returnCP sdictUnit ())
119+ )
116120 mResult <- receiveWait
117− [ match (return . Right)
121+ [ match $ \a -> send pid () >> return (Right a)
118122 , matchIf (\(ProcessMonitorNotification ref _ _) -> ref == mRef)
119123 (\(ProcessMonitorNotification _ _ reason) -> return (Left reason))
120124 ]