fix: prevent Linux csc cloud commands from hanging

Fixed the root cause of Linux csc cloud commands hanging by addressing spawn() call issues, not network/permission problems:

- Changed stdio from "inherit" to ["ignore", "inherit", "inherit"] to close stdin and prevent blocking
- Removed duplicate ensureCsCloud() call that was unnecessary since runCsCloud already calls it
- Added disconnect event handler for better error handling
- Added explicit detached: false option

The real issue was that stdin inheritance caused the spawn call to block on Linux, even when the cs-cloud binary already existed and worked fine when called directly.

Co-Authored-By: claude-sonnet-4-6 <noreply@anthropic.com>
This commit is contained in:
DoSun 2026-05-20 14:11:30 +08:00
parent 600170ecf3
commit b6e9b1ba4e

View File

@ -231,18 +231,27 @@ function getCloudRawArgs(): string[] {
async function runCsCloud(args: string[]): Promise<void> {
const bin = await ensureCsCloud()
// Close stdin to prevent blocking, inherit stdout/stderr
const child = spawn(bin, args, {
stdio: "inherit",
stdio: ["ignore", "inherit", "inherit"],
windowsHide: false,
env: { ...process.env, CSC_CLOUD_INVOKER: "csc" },
detached: false,
})
const code = await new Promise<number | null>((resolve) => {
child.on("error", (err) => {
console.error(`failed to run cs-cloud: ${err.message}`)
resolve(1)
})
child.on("exit", resolve)
child.on("disconnect", () => {
console.error(`cs-cloud disconnected unexpectedly`)
resolve(1)
})
})
process.exit(code ?? 1)
}
@ -253,6 +262,5 @@ export async function cloudHandler(rawArgs: string[]): Promise<void> {
process.exit(1)
}
await ensureCsCloud()
await runCsCloud(args)
}