Skip to content

Fix waitForProcess not closing process handles with delegate_ctlc #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 9, 2022

Conversation

robx
Copy link
Contributor

@robx robx commented Feb 3, 2022

I believe this might address #226, which I've run across myself when interrupting processes spawned with delegate_ctlc within withCreateProcess. It turns out this isn't a race condition (though I'm not saying there are none), it's just that the first withCreateProcess call fails to close the handle when it throws UserInterrupt.

There's a test case that covers the original behaviour I saw (an uncaught exception when the subprocess is interrupted), and then a couple of test cases narrowing down to the actual bug.

I haven't tested this on Windows, and I'm not sure to what extent the tests make sense there -- we might need to adapt or skip them.

testKillDoubleWait
putStrLn ">>> Tests passed successfully"

run :: String -> IO () -> IO ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this update!

@robx
Copy link
Contributor Author

robx commented Feb 7, 2022

I pushed some fixes for the CI failures. Once they pass I'd still like to clean up the commits a little.

EDIT: This is done now (well, hoping the tests will pass next time they run.)

@@ -725,8 +729,6 @@ waitForProcess ph@(ProcessHandle _ delegating_ctlc _) = lockWaitpid $ do
OpenExtHandle ph' job' -> do
closePHANDLE ph'
closePHANDLE job'
when delegating_ctlc $
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to remove this code entirely? Is this because it's Windows-only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, see also the commit message:

Additionally, remove endDelegateControlC entirely from the Windows-only
OpenExtHandle branch, where it's a no-op and was also in the wrong place.

It seemed wrong to leave the misleading previous version, but also weird to write some
no-op version of the fix here since delegating_ctlc has no effect on Windows.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an explicit comment in the code explaining why it's not needed would be a good thing. Otherwise someone may think it was just an oversight and add it back in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is done now

robx added 4 commits February 8, 2022 16:57
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.
@robx
Copy link
Contributor Author

robx commented Feb 8, 2022

I ended up skipping those tests with kill -INT, etc. on Windows, largely because I'm not sure how much sense they make, but also a little bit because they're hard to debug via CI.

Copy link
Collaborator

@snoyberg snoyberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you!

@snoyberg snoyberg merged commit de96ec0 into haskell:master Feb 9, 2022
@robx robx deleted the fix-ctlc-wait branch July 12, 2022 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants