Repository navigation
[Bug]: ChildProcess emits "close" before stdout/stderr streams are drained, hanging for-await + on("close") callers #2017
Replies: 2 comments 1 reply
|
Nice write-up, and I can confirm it's still on Workaround for extension authors (works in both Node and Tinycast): create the import { once } from "node:events";
const child = spawn(cmd, args);
const closed = once(child, "close"); // attach first
let out = "", err = "";
for await (const chunk of child.stdout) out += chunk;
for await (const chunk of child.stderr) err += chunk;
const [code] = await closed;Possible fix in the shim, closer to Node's semantics: emit // in the exit.then(...) handler, replacing the current queueMicrotask block
queueMicrotask(() => this.emit("exit", raw.status, raw.signal ?? null));
const done = (s) => new Promise((r) => finished(s, () => r()));
Promise.all([done(this.stdout), done(this.stderr)])
.then(() => this.emit("close", raw.status, raw.signal ?? null));
setImmediate(() => {
for (const s of [this.stdout, this.stderr]) if (s.readableFlowing === null) s.resume();
});I tested it against a small simulation of the shim (PassThrough streams ended in one shot, like the host reply):
Happy to open a PR if that's useful. |
|
i am no longer working on raycast extensions right now. i am working on tinycast native extension engine. and raycast extension will be in a separate repo to maintain in the future. i have stated that in #1888 here that raycast extension compatibility is paused for now. if this is really important you can have it in your own fork for now. later u can open pr |
Uh oh!
There was an error while loading. Please reload this page.
Existing discussions
What happened?
In Tinycast's
child_process.spawnshim,ChildProcessemits"close"beforestdoutandstderrhave been read to end. Any caller that consumeschild.stdout/child.stderrwithfor awaitand then awaitschild.on("close", ...)hangs forever until Tinycast times out the command.In
ChildProcess._startinnode-shims.js:In Node,
"close"waits until the child has exited and its stdio streams have closed. Here,"close"fires on the very next microtask afterend(), while afor awaitloop overchild.stdoutandchild.stderrtakes multiple microtasks to finish. By the time the caller attacheschild.on("close", resolve),"close"has already been emitted, so the promise never settles.Minimal pattern (works in Node 26.13.1, hangs in Tinycast
0.17.0):I hit this with an older imported copy of the Raycast Music extension (
fedevitaledev/music, pre-#31596), wherecurrently-playing-menu-barand 6 other commands hung onsw_versand repeatedly hit"The menu bar command timed out.". Updating the extension to the latest store build (which switched topromisify(execFile)) resolved it for me, so this is not blocking me anymore.I saw in
docs/not-planned.mdthat Raycast compatibility work has stopped — feel free to close if this falls under that, otherwise deferring"close"untilstdoutandstderrhave emitted"end"/"close"(or matching Node's stream-close ordering) would avoid silent hangs for extensions using this pattern.Steps to reproduce
spawn("sw_vers", ["-productVersion"]), readschild.stdoutandchild.stderrviafor await, and then awaitsnew Promise((r) => child.on("close", r))(for example, pre-2026-09-28fedevitaledev/music'scurrently-playing-menu-barorcurrently-playing).sw_versexits with status 0 immediately, but the command never resolves and eventually hits the 60s timeout (The menu bar command timed out.).Screenshots or recording
No response
Tinycast version + channel
0.17.0 stable
macOS version
27.2.1
I confirm that:
All reactions