Open mattfysh opened 1 month ago
Not sure if it is related:
OS:
System Version: macOS 14.6.1 (23G93)
Kernel Version: Darwin 23.6.0 (arm64)
Bun version:
1.1.29
Files:
bun ./src/index.ts
:
import { resolve } from "node:path";
const nodeSubProcess = Bun.spawn({
cmd: ["node", "./src/node/hello.js"],
cwd: resolve(import.meta.dir, ".."),
ipc(message) {
console.log("bun", message, "from node");
},
stdio: ["inherit", "inherit", "inherit"],
serialization: "json",
});
setInterval(() => {
nodeSubProcess.send("123");
}, 2000);
process.on("exit", () => {
nodeSubProcess.kill();
});
./src/node/hello.js
:
process.on("message", (msg) => {
console.log("i am node:", msg, "from bun");
process.send("i got " + msg);
});
process.on("uncaughtException", (a, b) => {
console.error(a, b);
});
// keep it running
setInterval(() => {}, 1000);
The output looks like:
SyntaxError: Unexpected token '', ""123"" is not valid JSON
at parse (<anonymous>)
at parseChannelMessages (node:internal/child_process/serialization:152:15)
at parseChannelMessages.next (<anonymous>)
at channel.onread (node:internal/child_process:624:18) uncaughtException
SyntaxError: Unexpected token '', ""123"" is not valid JSON
at parse (<anonymous>)
at parseChannelMessages (node:internal/child_process/serialization:152:15)
at parseChannelMessages.next (<anonymous>)
at channel.onread (node:internal/child_process:624:18) uncaughtException
.
.
.
I think this could be related - the character that trips up the JSON parser does not render visibly, so if you're logging the contents of the json string you're parsing you might not see the error initially. try encoding the string into a buffer then logging the bytes (eg. as hex) - you'll see it there
Looks like this broke in v1.1.25. Tested with: https://bun.sh/docs/api/spawn#ipc-between-bun-node-js
According to git bisect and bun-pr
this is where it broke: d55b5cc169c4b4661d28ce588ed0d0756122e3c9 (https://github.com/oven-sh/bun/pull/13381)
My Zig's no good but I hope this helps. Maybe one for the Head Baker @Jarred-Sumner
What version of Bun is running?
1.1.27+267afa293
What platform is your computer?
Darwin 23.6.0 arm64 arm
What steps can reproduce the bug?
index.ts
child.py
What is the expected behavior?
What do you see instead?
Note the
\x01
byteAdditional information
The following code run with node produces the correct result: