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

windows: set job object for executor and children #24214

Merged
merged 2 commits into from
Oct 16, 2024
Merged

Conversation

tgross
Copy link
Member

@tgross tgross commented Oct 15, 2024

On Windows, if the raw_exec driver's executor exits, the child processes are not also killed. Create a Windows "job object" (not to be confused with a Nomad job) and add the executor to it. Child processes of the executor will inherit the job automatically. When the handle to the job object is freed (on executor exit), the job itself is destroyed and this causes all processes in that job to exit.

Fixes: #23668
Ref: https://hashicorp.atlassian.net/browse/NET-11234
Ref: https://learn.microsoft.com/en-us/windows/win32/procthread/job-objects

Note: automated testing for this will need to be end-to-end but we're not running Windows on nightly anymore. I've verified the behavior works as expected using Process Explorer. Killing the executor kills all child processes as expected. Killing the root child process causes the executor to exit (as usual) and that in turn kills any child processes that didn't exit already.

Edit: added tests, which requires changing what runs in CI as well

On Windows, if the `raw_exec` driver's executor exits, the child processes are
not also killed. Create a Windows "job object" (not to be confused with a Nomad
job) and add the executor to it. Child processes of the executor will inherit
the job automatically. When the handle to the job object is freed (on executor
exit), the job itself is destroyed and this causes all processes in that job to
exit.

Fixes: #23668
Ref: https://learn.microsoft.com/en-us/windows/win32/procthread/job-objects
@tgross
Copy link
Member Author

tgross commented Oct 15, 2024

As noted in sidebar conversation I'm going to get drivers/shared/executor running on Windows and add a test for this there.

@@ -237,103 +236,6 @@ func TestRawExecDriver_StartWait(t *testing.T) {
require.NoError(harness.DestroyTask(task.ID, true))
}

func TestRawExecDriver_StartWaitRecoverWaitStop(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note to reviewers: this is moved to driver_unix_test.go unchanged, including any modernization to use shoenig/test, t.Cleanup, etc. I'll take a second pass over these files in a separate refactoring PR to do all that.

@@ -59,15 +59,6 @@ var (
compute = topology.Compute()
)

type testExecCmd struct {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note to reviewers: this whole file is marked !windows now, so I moved these helpers into utils_test.go

drivers/rawexec/driver_windows_test.go Outdated Show resolved Hide resolved
@tgross tgross added backport/ent/1.7.x+ent Changes are backported to 1.7.x+ent backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/1.9.x backport to 1.9.x release line labels Oct 16, 2024
@tgross tgross force-pushed the windows-executor-orphan branch from e066745 to a855e50 Compare October 16, 2024 13:01
@tgross tgross merged commit 6b8ddff into main Oct 16, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/ent/1.7.x+ent Changes are backported to 1.7.x+ent backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/1.9.x backport to 1.9.x release line theme/driver/raw_exec theme/platform-windows type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows -> Raw exec = Broken with 1.8.2
2 participants