Skip to content

Commit 8227693

Browse files
committed
Fix waitForProcess not closing the handle when raising delegated Ctrl-C
endDelegateControlC throws UserInterrupt, which would cause modifyProcessHandle to roll back, leaving the handle open despite the waitpid call. Instead, we postpone the call to endDelegateControlC, as is already the case in getProcessExitCode. Additionally, remove endDelegateControlC entirely from the Windows-only OpenExtHandle branch, where it's a no-op and was also in the wrong place.
1 parent dfe94f5 commit 8227693

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

System/Process.hs

+5-7
Original file line numberDiff line numberDiff line change
@@ -703,15 +703,15 @@ waitForProcess ph@(ProcessHandle _ delegating_ctlc _) = lockWaitpid $ do
703703
OpenHandle h -> do
704704
-- don't hold the MVar while we call c_waitForProcess...
705705
e <- waitForProcess' h
706-
e' <- modifyProcessHandle ph $ \p_' ->
706+
(e', was_open) <- modifyProcessHandle ph $ \p_' ->
707707
case p_' of
708-
ClosedHandle e' -> return (p_', e')
708+
ClosedHandle e' -> return (p_', (e', False))
709709
OpenExtHandle{} -> fail "waitForProcess(OpenExtHandle): this cannot happen"
710710
OpenHandle ph' -> do
711711
closePHANDLE ph'
712-
when delegating_ctlc $
713-
endDelegateControlC e
714-
return (ClosedHandle e, e)
712+
return (ClosedHandle e, (e, True))
713+
when (was_open && delegating_ctlc) $
714+
endDelegateControlC e
715715
return e'
716716
#if defined(WINDOWS)
717717
OpenExtHandle h job -> do
@@ -725,8 +725,6 @@ waitForProcess ph@(ProcessHandle _ delegating_ctlc _) = lockWaitpid $ do
725725
OpenExtHandle ph' job' -> do
726726
closePHANDLE ph'
727727
closePHANDLE job'
728-
when delegating_ctlc $
729-
endDelegateControlC e
730728
return (ClosedHandle e, e)
731729
return e'
732730
#else

0 commit comments

Comments
 (0)