Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

doctorpangloss
Copy link

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.

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.
}

if (!AssignProcessToJobObject(hJob, getPidHandle())) {
throw new RuntimeException("Failed to attach to job " + Native.getLastError());
Copy link
Collaborator

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.

Copy link
Author

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)
Copy link
Collaborator

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?

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