Skip to content

Commit deadc44

Browse files
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.
1 parent 5bed8d1 commit deadc44

File tree

1 file changed

+5
-7
lines changed
  • src/Control/Distributed/Process

1 file changed

+5
-7
lines changed

src/Control/Distributed/Process/Node.hs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,10 @@ import Control.Distributed.Process.Internal.Messaging
205205
)
206206
import Control.Distributed.Process.Internal.Primitives
207207
( register
208-
, finally
209208
, receiveWait
210209
, match
211210
, sendChan
212-
, catch
211+
, try
213212
, unwrapMessage
214213
)
215214
import Control.Distributed.Process.Internal.Types (SendPort, Tracer(..))
@@ -355,11 +354,10 @@ closeLocalNode node = do
355354
runProcess :: LocalNode -> Process () -> IO ()
356355
runProcess 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
365363
forkProcess :: LocalNode -> Process () -> IO ProcessId

0 commit comments

Comments
 (0)