-
Notifications
You must be signed in to change notification settings - Fork 84
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
Use Job objects in lieu of a shutdown hook on Windows. #133
base: master
Are you sure you want to change the base?
Conversation
Shutdown hooks have bad behavior on Windows. Using Windows Job objects ensure child processes die when the parent process (the NuProcess caller) dies, regardless of the circumstances that caused the JVM running NuProcess died.
508e8f3
to
a484ea9
Compare
} | ||
|
||
if (!AssignProcessToJobObject(hJob, getPidHandle())) { | ||
throw new RuntimeException("Failed to attach to job " + Native.getLastError()); |
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.
You're almost certainly going to leak a process if this happens. start
will catch this exception and (from my own changes) log it, and then return without the process ever being terminated.
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.
What should I do?
@@ -226,6 +222,8 @@ public void setProcessHandler(NuProcessHandler processHandler) | |||
|
|||
NuProcess start(List<String> commands, String[] environment, Path cwd) |
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.
Shouldn't you also make changes to run
below so it uses jobs too?
Shutdown hooks have bad behavior on Windows. Using Windows Job objects
ensure child processes die when the parent process (the NuProcess
caller) dies, regardless of the circumstances that caused the JVM
running NuProcess died.