diff --git a/nodejs/src/client.ts b/nodejs/src/client.ts index 5fdbf0358..f2876c675 100644 --- a/nodejs/src/client.ts +++ b/nodejs/src/client.ts @@ -199,6 +199,7 @@ function getBundledCliPath(): string { * ``` */ export class CopilotClient { + private cliStartTimeout: ReturnType | null = null; private cliProcess: ChildProcess | null = null; private connection: MessageConnection | null = null; private socket: Socket | null = null; @@ -540,6 +541,10 @@ export class CopilotClient { } this.cliProcess = null; } + if (this.cliStartTimeout) { + clearTimeout(this.cliStartTimeout); + this.cliStartTimeout = null; + } this.state = "disconnected"; this.actualPort = null; @@ -613,6 +618,11 @@ export class CopilotClient { this.cliProcess = null; } + if (this.cliStartTimeout) { + clearTimeout(this.cliStartTimeout); + this.cliStartTimeout = null; + } + this.state = "disconnected"; this.actualPort = null; this.stderrBuffer = ""; @@ -1522,7 +1532,7 @@ export class CopilotClient { }); // Timeout after 10 seconds - setTimeout(() => { + this.cliStartTimeout = setTimeout(() => { if (!resolved) { resolved = true; reject(new Error("Timeout waiting for CLI server to start"));