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

Workaround for #9041 #9580

Merged
merged 10 commits into from
Mar 29, 2024
3 changes: 2 additions & 1 deletion src/bun.js/javascript.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,8 @@ pub const VirtualMachine = struct {
}

const old_log = jsc_vm.log;
var log = logger.Log.init(jsc_vm.allocator);
// the logger can end up being called on another thread, it must not use threadlocal Heap Allocator
var log = logger.Log.init(bun.default_allocator);
defer log.deinit();
jsc_vm.log = &log;
jsc_vm.bundler.resolver.log = &log;
Expand Down
12 changes: 12 additions & 0 deletions src/js/node/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3388,9 +3388,21 @@ var require_readable = __commonJS({
};

Readable.fromWeb = function (readableStream, options) {
// We cache .stream() calls for file descriptors
// This won't create a new ReadableStream each time.
let bunStdinStream = Bun.stdin.stream();
if (readableStream === bunStdinStream) {
return bunStdinStream;
}

return webStreamsAdapters.newStreamReadableFromReadableStream(readableStream, options);
};
Readable.toWeb = function (streamReadable, options) {
// Workaround for https://github.com/oven-sh/bun/issues/9041
if (streamReadable === process.stdin) {
return Bun.stdin.stream();
}

return webStreamsAdapters.newReadableStreamFromStreamReadable(streamReadable, options);
};
Readable.wrap = function (src, options) {
Expand Down
28 changes: 28 additions & 0 deletions test/regression/issue/09041.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { test, expect } from "bun:test";
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
import { join } from "path";
import { $ } from "bun";
import { cp, rm } from "fs/promises";

test("09041", async () => {
const out = tempDirWithFiles("09041", {
"09041-fixture.mjs": await Bun.file(join(import.meta.dir, "09041", "09041-fixture.mjs")).text(),
"09041-fixture.test.js": await Bun.file(join(import.meta.dir, "09041", "09041-fixture-test.txt")).text(),
"package.json": `{}`,
});

let { exited, stderr, stdout } = Bun.spawn({
cmd: [bunExe(), "test"],
cwd: out,
env: bunEnv,
stdio: ["ignore", "pipe", "pipe"],
});

expect(await exited).toBe(0);
const err = await new Response(stderr).text();
expect(err).toContain("1 pass");
expect(err).toContain("0 fail");
const std = await new Response(stdout).text();

expect(std.length).toBeGreaterThan(1024 * 1024);
}, 10000);
21 changes: 21 additions & 0 deletions test/regression/issue/09041/09041-fixture-test.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/regression/issue/09041/09041-fixture.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading