-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Ensure non-blocking process wait and correctly report process exit status #3419
Conversation
This still needs to be tested on windows, CI doesnt run the process tests on windows. |
33fe254
to
9348421
Compare
Ok, here we go! Tests run fine on windows! 🎉 |
@cquinn can you take a look at this? |
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.
I think this looks good.
packages/process/_process.pony
Outdated
@@ -34,13 +34,95 @@ primitive _EAGAIN | |||
primitive _EINVAL | |||
fun apply(): I32 => 22 | |||
|
|||
primitive WNOHANG |
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.
Maybe a Comment here to describe what WNOHANG
represents. Also, would it be possible to make it _WNOHANG
?
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.
The _ is a good catch. That should be changed.
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.
WNOHANG should be _WNOHANG as cquinn noted.
I don't think it needs a comment on what it is, as none of the other primitives do. If we want that, it should be part of a separate PR.
9348421
to
6eaf1a3
Compare
d88817c
to
989b563
Compare
@SeanTAllen all good to go from my side. How about you? |
@mfelsche 0.34.1 has been released. you can merge this whenever. can you add the release notes to the 0.34.2 issue? |
by calling waitpid with WNOHANG on posix and doing the equivalent on windows and if the process didnt exit yet, start a timer and poll the process. But only create timers etc. if the process didnt finish in the first try to save resources in the normal case.
So users of ProcessNotify are properly notified of how their process exited. If it was killed by a signal, child_exit_status will be a Signaled instance containing the signal number that terminated the process (only on POSIX).
It was depending on being executed in the directory of its source, which was not true. THe test accidentally created an empty executable version of that file, while ensuring it to be executable. This was polluting the test directory. Now everything is put inside a temp dir, which is cleaned afterwards.
02ba6a1
to
10011c0
Compare
10011c0
to
a6f5a36
Compare
@mfelsche don't forget to SQUASH when you merge this! 😉 I forget sometimes, thought I would remind you just in case. |
Thanks, much appreciated! |
Waiting or a process to finish was potentially blocking both on windows and posix systems. It was only ever called when the child process was killed beforehand or has closed both stdout and stderr, so the actual risk to block was low, but still. Now it calls
waitpid
(and the windows equivalent) withWNOHANG
(on windows with timeout of 0) to ensure it does not block. If the process is still running at that point, a timer is scheduled to poll the process using the non-blockingwaitpid
.During testing I discovered that processes terminated by signals were usually reported as exited with exit-code 0, which is wrong. I changed the
ProcessNotify.dispose
signature to receive aSignaled
orExited
class containing signal number or exit code.This works pretty well, the only case this does not catch is, when a process exits and sets an exit-code in a signal handler.
ProcessNotify.dispose
will be called withSignaled
, not withExited
and the exit code is basically lost. But I still prefer this.As this is a breaking change, I thought to keep it as draft at first, in order to discuss it.
I would consider the non-blocking waitpid call as internal and the improved exit status reporting as actually fixing a bug, that is why I didn't create an RFC for this.