@@ -256,24 +256,7 @@ startProcess pConfig'@ProcessConfig {..} = liftIO $ do
256256 -- Process didn't exit yet, let's terminate it and
257257 -- then call waitForProcess ourselves
258258 Left _ -> do
259- eres <- try $ P. terminateProcess pHandle
260- case eres of
261- Left e
262- -- On Windows, with the single-threaded runtime, it
263- -- seems that if a process has already exited, the
264- -- call to terminateProcess will fail with a
265- -- permission denied error. To work around this, we
266- -- catch this exception and then immediately
267- -- waitForProcess. There's a chance that there may be
268- -- other reasons for this permission error to appear,
269- -- in which case this code may allow us to wait too
270- -- long for a child process instead of erroring out.
271- -- Recommendation: always use the multi-threaded
272- -- runtime!
273- | isPermissionError e && not multiThreadedRuntime && isWindows ->
274- pure ()
275- | otherwise -> throwIO e
276- Right () -> pure ()
259+ terminateProcess pHandle
277260 ec <- P. waitForProcess pHandle
278261 success <- atomically $ tryPutTMVar pExitCode ec
279262 evaluate $ assert success ()
@@ -282,6 +265,26 @@ startProcess pConfig'@ProcessConfig {..} = liftIO $ do
282265 where
283266 pConfig = clearStreams pConfig'
284267
268+ terminateProcess pHandle = do
269+ eres <- try $ P. terminateProcess pHandle
270+ case eres of
271+ Left e
272+ -- On Windows, with the single-threaded runtime, it
273+ -- seems that if a process has already exited, the
274+ -- call to terminateProcess will fail with a
275+ -- permission denied error. To work around this, we
276+ -- catch this exception and then immediately
277+ -- waitForProcess. There's a chance that there may be
278+ -- other reasons for this permission error to appear,
279+ -- in which case this code may allow us to wait too
280+ -- long for a child process instead of erroring out.
281+ -- Recommendation: always use the multi-threaded
282+ -- runtime!
283+ | isPermissionError e && not multiThreadedRuntime && isWindows ->
284+ pure ()
285+ | otherwise -> throwIO e
286+ Right () -> pure ()
287+
285288foreign import ccall unsafe " rtsSupportsBoundThreads"
286289 multiThreadedRuntime :: Bool
287290
0 commit comments