-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
464ab29
fix a hang
paperdave 95046f5
Merge remote-tracking branch 'origin/main' into dave/win/spawn-job-obj
paperdave f4219d7
this was a watch specific bug
paperdave 8ffa450
fix mistake
paperdave 2981dbc
Merge branch 'main' into dave/win/spawn-job-obj
Jarred-Sumner ecc46f2
some dx
paperdave ed8a70f
hello
paperdave File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { spawn } from "bun"; | ||
import { it, expect } from "bun:test"; | ||
import { bunEnv, bunExe } from "harness"; | ||
import { join } from "node:path"; | ||
|
||
it("does not hang", async () => { | ||
const subprocess = spawn({ | ||
cmd: [bunExe(), "test", join(import.meta.dirname, "job-object-bug.ts")], | ||
env: bunEnv, | ||
stdio: ["ignore", "pipe", "pipe"], | ||
}); | ||
await Bun.readableStreamToText(subprocess.stdout); | ||
expect(await subprocess.exited).toBe(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { spawn } from "bun"; | ||
import { bunEnv, bunExe } from "harness"; | ||
import { join } from "node:path"; | ||
|
||
// prior, this would hang on Windows if you ran this with a pipe | ||
|
||
const run = spawn({ | ||
cmd: [bunExe(), "--watch", join(import.meta.dirname, "empty.js")], | ||
stdout: "inherit", | ||
stderr: "inherit", | ||
stdin: "ignore", | ||
env: bunEnv, | ||
}); | ||
await Bun.sleep(250); | ||
run.kill(9); | ||
await run.exited; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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.
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 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.
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.
Looks good now 👍