1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-30 02:59:11 -05:00
denoland-deno/tests/specs/node/child_process_extra_pipes/main.ts
Nathan Whitaker 7c57105cc4
fix(ext/node): only set our end of child process pipe to nonblocking mode (#26495)
Fixes playwright on linux, as reported in
https://github.com/denoland/deno/issues/16899#issuecomment-2378268454.

The issue was that we were opening the socket in nonblocking mode, which
meant that subprocesses trying to use it would get a `EWOULDBLOCK` error
(unexpectedly). The fix here is to only set nonblocking mode on our end
(which we need to use asynchronously)
2024-10-23 21:13:30 -07:00

38 lines
742 B
TypeScript

import child_process from "node:child_process";
import console from "node:console";
const child = child_process.spawn("./test-pipe/target/debug/test-pipe", [], {
stdio: ["inherit", "inherit", "inherit", "ignore", "pipe"],
});
const extra = child.stdio[4];
if (!extra) {
throw new Error("no extra pipe");
}
const p = Promise.withResolvers<void>();
let got = "";
child.on("close", () => {
console.log("child closed");
console.log("got:", got);
if (got === "hello world") {
p.resolve();
} else {
p.reject(new Error(`wanted "hello world", got "${got}"`));
}
});
extra.on("data", (d) => {
got += d.toString();
});
extra.on("close", () => {
console.log("pipe closed");
});
extra.write("start");
await p.promise;