-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: prevent segfault in auto-install due to log allocator mismatch #26031
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 all commits
1df0010
5b05fdf
24299ae
d7969a8
81dfac2
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 |
|---|---|---|
|
|
@@ -84,3 +84,97 @@ test("--install=fallback to install missing packages", async () => { | |
| expect(stderr?.toString("utf8")).not.toContain("error: Cannot find package 'is-odd'"); | ||
| expect(stdout?.toString("utf8")).toBe("true false\n"); | ||
| }); | ||
|
|
||
| // Regression test: Auto-install should not crash with a segfault when logging errors. | ||
| // The crash occurred because the PackageManager's log used an allocator | ||
| // that could become invalid during transpilation. | ||
| describe("autoinstall should not crash on resolution errors", () => { | ||
| test("should handle missing package gracefully without segfault", async () => { | ||
| const dir = tmpdirSync(); | ||
| mkdirSync(dir, { recursive: true }); | ||
|
|
||
| // Create a project that imports a non-existent package | ||
| await Promise.all([ | ||
| Bun.write( | ||
| join(dir, "index.js"), | ||
| "import nonExistentPackage from 'this-package-does-not-exist-12345'; console.log(nonExistentPackage);", | ||
| ), | ||
| Bun.write( | ||
| join(dir, "package.json"), | ||
| JSON.stringify({ | ||
| name: "test-autoinstall-crash", | ||
| type: "module", | ||
| }), | ||
| ), | ||
| ]); | ||
|
|
||
| // Run without node_modules to trigger auto-install code path | ||
| const { exitCode, stderr } = Bun.spawnSync({ | ||
| cmd: [bunExe(), join(dir, "index.js")], | ||
| cwd: dir, | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
|
|
||
| const stderrText = stderr?.toString("utf8") ?? ""; | ||
|
|
||
| // Should NOT crash with segfault (exit codes 128+N indicate death by signal N) | ||
| expect(exitCode).not.toBe(134); // SIGABRT (128 + 6) | ||
| expect(exitCode).not.toBe(139); // SIGSEGV (128 + 11) | ||
|
|
||
| // Should contain a normal error message about the missing package | ||
| expect(stderrText).toContain("this-package-does-not-exist-12345"); | ||
| }); | ||
|
Comment on lines
+92
to
+128
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 LGTM! Consider reordering assertions for better debugging. The test correctly validates the segfault regression. Per coding guidelines, checking stderr content before exit code provides more useful error messages on test failure. Consider moving stderr assertions before exit code assertions. ♻️ Suggested reordering const stderrText = stderr?.toString("utf8") ?? "";
- // Should NOT crash with segfault (exit codes 128+N indicate death by signal N)
- expect(exitCode).not.toBe(134); // SIGABRT (128 + 6)
- expect(exitCode).not.toBe(139); // SIGSEGV (128 + 11)
-
// Should NOT contain crash indicators
expect(stderrText).not.toContain("Segmentation fault");
expect(stderrText).not.toContain("Bun has crashed");
// Should contain a normal error message about the missing package
expect(stderrText).toContain("this-package-does-not-exist-12345");
+
+ // Should NOT crash with segfault (exit codes 128+N indicate death by signal N)
+ expect(exitCode).not.toBe(134); // SIGABRT (128 + 6)
+ expect(exitCode).not.toBe(139); // SIGSEGV (128 + 11)🤖 Prompt for AI Agents
Comment on lines
+112
to
+128
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 Consider checking stderr before exit code for better failure diagnostics. Based on coding guidelines, expecting output before exit code provides more useful error messages on test failure. If the process crashes, seeing what stderr contained helps diagnose the issue. 💡 Suggested reorder const { exitCode, stderr } = Bun.spawnSync({
cmd: [bunExe(), join(dir, "index.js")],
cwd: dir,
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});
const stderrText = stderr?.toString("utf8") ?? "";
- // Should NOT crash with segfault (exit codes 128+N indicate death by signal N)
- expect(exitCode).not.toBe(134); // SIGABRT (128 + 6)
- expect(exitCode).not.toBe(139); // SIGSEGV (128 + 11)
-
// Should contain a normal error message about the missing package
expect(stderrText).toContain("this-package-does-not-exist-12345");
+
+ // Should NOT crash with segfault (exit codes 128+N indicate death by signal N)
+ expect(exitCode).not.toBe(134); // SIGABRT (128 + 6)
+ expect(exitCode).not.toBe(139); // SIGSEGV (128 + 11)🤖 Prompt for AI Agents |
||
|
|
||
| test("should handle resolution during transpilation without segfault", async () => { | ||
| const dir = tmpdirSync(); | ||
| mkdirSync(dir, { recursive: true }); | ||
|
|
||
| // Create a TypeScript project that triggers transpilation + resolution | ||
| await Promise.all([ | ||
| Bun.write( | ||
| join(dir, "index.ts"), | ||
| ` | ||
| // TypeScript file to trigger transpilation | ||
| const x: string = "hello"; | ||
| import pkg from 'another-nonexistent-pkg-67890'; | ||
| console.log(x, pkg); | ||
| `, | ||
| ), | ||
| Bun.write( | ||
| join(dir, "package.json"), | ||
| JSON.stringify({ | ||
| name: "test-autoinstall-ts-crash", | ||
| type: "module", | ||
| }), | ||
| ), | ||
| Bun.write( | ||
| join(dir, "tsconfig.json"), | ||
| JSON.stringify({ | ||
| compilerOptions: { | ||
| target: "ESNext", | ||
| module: "ESNext", | ||
| }, | ||
| }), | ||
| ), | ||
| ]); | ||
|
|
||
| const { exitCode, stderr } = Bun.spawnSync({ | ||
| cmd: [bunExe(), join(dir, "index.ts")], | ||
| cwd: dir, | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
|
|
||
| const stderrText = stderr?.toString("utf8") ?? ""; | ||
|
|
||
| // Should NOT crash with segfault (exit codes 128+N indicate death by signal N) | ||
| expect(exitCode).not.toBe(134); // SIGABRT (128 + 6) | ||
| expect(exitCode).not.toBe(139); // SIGSEGV (128 + 11) | ||
|
|
||
| // Should contain a normal error message | ||
| expect(stderrText).toContain("another-nonexistent-pkg-67890"); | ||
|
Comment on lines
+175
to
+185
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 Same suggestion: reorder assertions for better diagnostics on failure. Consistent with the first test, checking stderr content before exit codes provides more useful context if the test fails. ♻️ Suggested reordering const stderrText = stderr?.toString("utf8") ?? "";
+ // Should contain a normal error message
+ expect(stderrText).toContain("another-nonexistent-pkg-67890");
+
+ expect(stderrText).not.toContain("Segmentation fault");
+ expect(stderrText).not.toContain("Bun has crashed");
+
// Should NOT crash with segfault (exit codes 128+N indicate death by signal N)
expect(exitCode).not.toBe(134); // SIGABRT (128 + 6)
expect(exitCode).not.toBe(139); // SIGSEGV (128 + 11)
-
- expect(stderrText).not.toContain("Segmentation fault");
- expect(stderrText).not.toContain("Bun has crashed");
-
- // Should contain a normal error message
- expect(stderrText).toContain("another-nonexistent-pkg-67890");🤖 Prompt for AI Agents |
||
| }); | ||
| }); | ||
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.
🧹 Nitpick | 🔵 Trivial
Consider reordering assertions: check stderr before exit code for better diagnostics.
Per coding guidelines, when spawning processes in tests, expect output (stdout/stderr) before expecting exit code for more useful error messages on test failure. If these assertions fail, seeing the stderr content first provides more context.
♻️ Suggested reordering
const stderrText = stderr?.toString("utf8") ?? ""; + // Should contain a normal error message about the missing package + expect(stderrText).toContain("this-package-does-not-exist-12345"); + + // Should NOT contain crash indicators + expect(stderrText).not.toContain("Segmentation fault"); + expect(stderrText).not.toContain("Bun has crashed"); + // Should NOT crash with segfault (exit codes 128+N indicate death by signal N) expect(exitCode).not.toBe(134); // SIGABRT (128 + 6) expect(exitCode).not.toBe(139); // SIGSEGV (128 + 11) - - // Should NOT contain crash indicators - expect(stderrText).not.toContain("Segmentation fault"); - expect(stderrText).not.toContain("Bun has crashed"); - - // Should contain a normal error message about the missing package - expect(stderrText).toContain("this-package-does-not-exist-12345");📝 Committable suggestion
🤖 Prompt for AI Agents