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

fix(windows spawn): use Job Object to manage subprocesses of subprocesses #11240

Merged
merged 7 commits into from
May 24, 2024

Conversation

paperdave
Copy link
Collaborator

What does this PR do?

See test case, note how --watch spawns two processes, but before, the kill in the outermost process would keep the innermost subprocess alive. Now, calling kill in the outermost process kills the whole tree. This was an issue if the caller of this process tree depended on standard io, which would not be closed before. Now, since the processes are dead, the standard io is closed.

Copy link
Contributor

github-actions bot commented May 21, 2024

@paperdave, your commit has failing tests :(

💪 2 failing tests Darwin AARCH64

  • test/cli/install/bun-install.test.ts 1 failing
  • test/js/node/tls/node-tls-context.test.ts 1 failing

💻 4 failing tests Darwin x64

  • test/cli/install/bun-create.test.ts 1 failing
  • test/cli/install/bun-upgrade.test.ts 1 failing
  • test/js/node/tls/node-tls-context.test.ts 1 failing
  • test/js/web/workers/worker.test.ts 1 failing

🐧💪 3 failing tests Linux AARCH64

  • test/cli/install/registry/bun-install-registry.test.ts 3 failing
  • test/integration/mysql2/mysql2.test.ts 2 failing
  • test/js/bun/http/serve.test.ts 1 failing

🪟💻 8 failing tests Windows x64 baseline

  • test/cli/install/bun-install.test.ts 41 failing
  • test/cli/install/bunx.test.ts 2 failing
  • test/js/bun/shell/bunshell.test.ts 1 failing
  • test/js/bun/spawn/spawn.test.ts SIGKILL
  • test/js/node/dns/node-dns.test.js 2 failing
  • test/js/node/http/node-http.test.ts 1 failing
  • test/js/node/process/process.test.js 2 failing
  • test/js/node/watch/fs.watchFile.test.ts 3 failing

🪟💻 9 failing tests Windows x64

  • test/cli/install/bunx.test.ts 1 failing
  • test/cli/install/migration/migrate.test.ts 1 failing
  • test/cli/install/registry/bun-install-registry.test.ts 3 failing
  • test/integration/esbuild/esbuild.test.ts 1 failing
  • test/js/bun/shell/bunshell.test.ts 1 failing
  • test/js/node/dns/node-dns.test.js 2 failing
  • test/js/node/http/node-http.test.ts 1 failing
  • test/js/node/process/process.test.js 2 failing
  • test/js/node/watch/fs.watchFile.test.ts SIGKILL

View logs

Copy link
Contributor

@gvilums gvilums left a comment

Choose a reason for hiding this comment

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

Looks good in general, see my comment about the race condition

Comment on lines 1723 to 1724
if (bun.windows.CreateJobObjectA(null, null)) |job|
_ = bun.windows.AssignProcessToJobObject(job, process.poller.uv.process_handle);
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the process has already spawned a child process and then exited by the time it's being assigned to the job object? See this blog for context. Not sure if this is an edge case we should care about, but might be relevant.

To do it the "right" way we might need to mess with libuv internals for process spawning, not sure if we want to do that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i moved this to just the code for --watch (libuv already does this and actually did it more correct than what i have here), and i followed the linked guide so that we spawn the process without this race. thank you.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good now 👍

@gvilums
Copy link
Contributor

gvilums commented May 22, 2024

Changes look good now, however there seems to be a test failure in watch.test.ts on windows - I'm not sure if it was there before, but I think it wasn't

@Jarred-Sumner
Copy link
Collaborator

I think the hot and watch tests need to pass before this PR can be merged

@paperdave

This comment was marked as resolved.

@paperdave paperdave marked this pull request as draft May 22, 2024 20:21
@paperdave paperdave marked this pull request as ready for review May 24, 2024 00:46
@Jarred-Sumner Jarred-Sumner merged commit c3157e2 into main May 24, 2024
48 of 53 checks passed
@Jarred-Sumner Jarred-Sumner deleted the dave/win/spawn-job-obj branch May 24, 2024 02:59
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.

None yet

3 participants