-
Notifications
You must be signed in to change notification settings - Fork 25
Ensure that waitForProcess is never called more than once (fixes #69)
#70
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
base: master
Are you sure you want to change the base?
Conversation
|
@snoyberg this is ready to go. I edited the PR description to include the exact execution sequence that I think led to the issue. |
46ddc7b to
218be46
Compare
waitForProcess is never called multiple times (fixes #69)waitForProcess is never called more than once (fixes #69)
|
Also note that this will allow us to further simplify the code if we choose to, to make sure that we can't possibly forget to put the |
|
Overall this looks OK to me, but to be honest this has been a very sensitive part of the code and I don't really remember all the different edge cases. @nh2 would you mind giving this a look over as well? |
|
Thanks @snoyberg for taking a look. I don't want to rush this in, but I have a (private) PR pending, that is blocked by this bug fix. So, naturally, I care about getting this merged. Is there anything I can do to help move this forward? Would it help if I add more verbose comments on how I think best to review this? |
|
I've pinged some people for review, but I'm not comfortable moving ahead on my own review alone, I know this code has gone through lots of revisions with lots of different bugs coming from each iteration. |
|
I see that @tomjaguarpaw already commented on that PR, so I'd defer to him. Personally, I find the change in code harder to parse than the original version. |
| _ :: ExitCode <- Async.poll waitingThread >>= \ case | ||
| -- Process already exited, nothing to do | ||
| Right _ec -> return () | ||
| Just r -> either throwIO return r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the time this will be a Right-value, but with delegate_ctlc this can be UserInterrupt, which we then re-throw here (see #73).
This fixes the issue described in #69:
This is what I think is happening:
waitingThreadhere:typed-process/src/System/Process/Typed.hs
Line 247 in 788209f
echoprocess terminates normally and thewaitingThreadreceivesAsyncCancelledright afterwaitForProcessreturns:typed-process/src/System/Process/Typed.hs
Line 226 in 788209f
ExitCode:waitForProcesshas concluded, butpExitCodeis still empty.typed-process/src/System/Process/Typed.hs
Line 250 in 788209f
waitCatchreturns aLeft-value here and we erroneously assume thatwaitForProcessdid not conclude yet.waitForProcessa second time which results in anIOExceptionof typeNoSuchThing:typed-process/src/System/Process/Typed.hs
Line 277 in 788209f
This PR always relies on the
waitingThreadto callwaitForProcessand by extension structures the code in a away so thatwaitForProcesscan only ever be called once.