From e9325d92be29247fbfde4a3c77e968c296bc9a6d Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Mon, 2 Feb 2026 21:15:28 +0700 Subject: [PATCH] fix: clear timeout handle to prevent event loop from staying alive --- packages/cli/src/utils/client.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/utils/client.ts b/packages/cli/src/utils/client.ts index e2fe2d02f..6f049151d 100644 --- a/packages/cli/src/utils/client.ts +++ b/packages/cli/src/utils/client.ts @@ -48,17 +48,26 @@ export async function connectToDaemon(options?: ConnectOptions): Promise | null = null const timeoutPromise = new Promise((_, reject) => { - setTimeout(() => { + timeoutHandle = setTimeout(() => { reject(new Error(`Connection timeout after ${timeout}ms`)) }, timeout) }) try { await Promise.race([connectPromise, timeoutPromise]) + // Clear the timeout so it doesn't keep the event loop alive + if (timeoutHandle) { + clearTimeout(timeoutHandle) + } client.subscribeAgentUpdates({ subscriptionId: `cli:${process.pid}` }) return client } catch (err) { + // Clear the timeout on error too + if (timeoutHandle) { + clearTimeout(timeoutHandle) + } await client.close().catch(() => {}) throw err }