From b6e9b1ba4e84850746332d74a2a9488e7ce34ae6 Mon Sep 17 00:00:00 2001 From: DoSun Date: Wed, 20 May 2026 14:11:30 +0800 Subject: [PATCH] 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 --- src/cli/handlers/cloud.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cli/handlers/cloud.ts b/src/cli/handlers/cloud.ts index 4fcf68ece..54bca2cb1 100644 --- a/src/cli/handlers/cloud.ts +++ b/src/cli/handlers/cloud.ts @@ -231,18 +231,27 @@ function getCloudRawArgs(): string[] { async function runCsCloud(args: string[]): Promise { 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((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 { process.exit(1) } - await ensureCsCloud() await runCsCloud(args) }