-
Notifications
You must be signed in to change notification settings - Fork 4.6k
spawnSync: do not forward SIGPWR on Linux #30956
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
4b9d469
ac02046
1b8f2ae
2d5b42e
7e2c283
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { expect, test } from "bun:test"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { symlinkSync } from "fs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { bunEnv, bunExe, isLinux, tempDir } from "harness"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { join } from "path"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Regression: spawnSync's signal-forwarding list included SIGPWR on Linux. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // JSC uses SIGPWR to suspend/resume threads for GC. Bun.openInEditor spawns a | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // detached thread per call that runs spawnSync; concurrent calls race on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // process-wide previous-handler table and can leave SIGPWR at SIG_DFL. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // next GC suspend then terminates the process with signal 30. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| test.skipIf(!isLinux)("spawnSync signal forwarding does not clobber JSC's SIGPWR handler", async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const sleepBin = Bun.which("sleep"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(sleepBin).toBeTruthy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| using dir = tempDir("spawnSync-sigpwr", { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "run.js": ` | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (let i = 0; i < 64; i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { Bun.openInEditor("0.2"); } catch {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| let junk = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (let i = 0; i < 2000; i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| junk.push({ a: new Uint8Array(4096).fill(i), b: { c: i } }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (let i = 0; i < 30; i++) Bun.gc(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("ok"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Make `code` (first in the editor preference list) resolve to `sleep`, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // each background spawnSync holds its signal-forwarding window open long | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // enough for threads to overlap. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| symlinkSync(sleepBin!, join(String(dir), "code")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| await using proc = Bun.spawn({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| cmd: [bunExe(), join(String(dir), "run.js")], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| env: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...bunEnv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| PATH: String(dir), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| EDITOR: "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| VISUAL: "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdout: "pipe", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| stderr: "inherit", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [stdout, exitCode] = await Promise.all([proc.stdout.text(), proc.exited]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(proc.signalCode).toBeNull(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(stdout.trim()).toBe("ok"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(exitCode).toBe(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win Pipe stderr for better CI failure diagnostics. With ♻️ Suggested change stdout: "pipe",
- stderr: "inherit",
+ stderr: "pipe",
});
- const [stdout, exitCode] = await Promise.all([proc.stdout.text(), proc.exited]);
+ const [stdout, stderr, exitCode] = await Promise.all([
+ proc.stdout.text(),
+ proc.stderr.text(),
+ proc.exited,
+ ]);
expect(proc.signalCode).toBeNull();
expect(stdout.trim()).toBe("ok");
+ if (exitCode !== 0) {
+ expect(stderr).toBe("");
+ }
expect(exitCode).toBe(0);Based on learnings: "In oven-sh/bun Jest/Bun test files under 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.