From 9fed8da67d7a03162835344f5ffe212179933e7a Mon Sep 17 00:00:00 2001 From: Adrien Friggeri Date: Tue, 3 Feb 2026 23:37:36 +0000 Subject: [PATCH] fix: clear timeout timer in sendAndWait to prevent process hang When idlePromise resolved first (successful response), the setTimeout timer kept running in the background, preventing Node.js from exiting until the timer fired. Fixes #136 --- nodejs/src/session.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nodejs/src/session.ts b/nodejs/src/session.ts index ba6b42d2..19da9bd1 100644 --- a/nodejs/src/session.ts +++ b/nodejs/src/session.ts @@ -167,11 +167,12 @@ export class CopilotSession { } }); + let timeoutId: ReturnType | undefined; try { await this.send(options); const timeoutPromise = new Promise((_, reject) => { - setTimeout( + timeoutId = setTimeout( () => reject( new Error( @@ -185,6 +186,9 @@ export class CopilotSession { return lastAssistantMessage; } finally { + if (timeoutId !== undefined) { + clearTimeout(timeoutId); + } unsubscribe(); } }