Skip to content

Commit 31befad

Browse files
Workaround for #9041 (#9580)
* Workaround for #9041 * Fix crash with auto install * Fixup this test * Update 09041.test.ts --------- Co-authored-by: Jarred Sumner <[email protected]>
1 parent 94b01b2 commit 31befad

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

src/bun.js/javascript.zig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,8 @@ pub const VirtualMachine = struct {
19251925
}
19261926

19271927
const old_log = jsc_vm.log;
1928-
var log = logger.Log.init(jsc_vm.allocator);
1928+
// the logger can end up being called on another thread, it must not use threadlocal Heap Allocator
1929+
var log = logger.Log.init(bun.default_allocator);
19291930
defer log.deinit();
19301931
jsc_vm.log = &log;
19311932
jsc_vm.bundler.resolver.log = &log;

src/js/node/stream.js

+12
Original file line numberDiff line numberDiff line change
@@ -3388,9 +3388,21 @@ var require_readable = __commonJS({
33883388
};
33893389

33903390
Readable.fromWeb = function (readableStream, options) {
3391+
// We cache .stream() calls for file descriptors
3392+
// This won't create a new ReadableStream each time.
3393+
let bunStdinStream = Bun.stdin.stream();
3394+
if (readableStream === bunStdinStream) {
3395+
return bunStdinStream;
3396+
}
3397+
33913398
return webStreamsAdapters.newStreamReadableFromReadableStream(readableStream, options);
33923399
};
33933400
Readable.toWeb = function (streamReadable, options) {
3401+
// Workaround for https://github.com/oven-sh/bun/issues/9041
3402+
if (streamReadable === process.stdin) {
3403+
return Bun.stdin.stream();
3404+
}
3405+
33943406
return webStreamsAdapters.newReadableStreamFromStreamReadable(streamReadable, options);
33953407
};
33963408
Readable.wrap = function (src, options) {

test/regression/issue/09041.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { test, expect } from "bun:test";
2+
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
3+
import { join } from "path";
4+
import { $ } from "bun";
5+
import { cp, rm } from "fs/promises";
6+
7+
test("09041", async () => {
8+
const out = tempDirWithFiles("09041", {
9+
"09041-fixture.mjs": await Bun.file(join(import.meta.dir, "09041", "09041-fixture.mjs")).text(),
10+
"09041-fixture.test.js": await Bun.file(join(import.meta.dir, "09041", "09041-fixture-test.txt")).text(),
11+
"package.json": `{}`,
12+
});
13+
14+
let { exited, stderr, stdout } = Bun.spawn({
15+
cmd: [bunExe(), "test"],
16+
cwd: out,
17+
env: bunEnv,
18+
stdio: ["ignore", "pipe", "pipe"],
19+
});
20+
21+
expect(await exited).toBe(0);
22+
const err = await new Response(stderr).text();
23+
expect(err).toContain("1 pass");
24+
expect(err).toContain("0 fail");
25+
const std = await new Response(stdout).text();
26+
27+
expect(std.length).toBeGreaterThan(1024 * 1024);
28+
}, 10000);

test/regression/issue/09041/09041-fixture-test.txt

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/regression/issue/09041/09041-fixture.mjs

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)