From b83c76cef26aadcfb18adddf87f88a067f47bbb9 Mon Sep 17 00:00:00 2001 From: Burke Holland Date: Tue, 20 Jan 2026 17:07:02 -0600 Subject: [PATCH 1/2] Fix timeout handling in CopilotSession to ensure process exists on close --- nodejs/src/session.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nodejs/src/session.ts b/nodejs/src/session.ts index ca9789c..26fc44a 100644 --- a/nodejs/src/session.ts +++ b/nodejs/src/session.ts @@ -145,11 +145,12 @@ export class CopilotSession { } }); + let timeoutId: NodeJS.Timeout | undefined; try { await this.send(options); const timeoutPromise = new Promise((_, reject) => { - setTimeout( + timeoutId = setTimeout( () => reject( new Error( @@ -159,10 +160,11 @@ export class CopilotSession { effectiveTimeout ); }); - await Promise.race([idlePromise, timeoutPromise]); + await Promise.race([idlePromise, timeoutPromise]); return lastAssistantMessage; } finally { + if (timeoutId) clearTimeout(timeoutId); unsubscribe(); } } From 251d6d3702347d4006373392e8e652170c724dcd Mon Sep 17 00:00:00 2001 From: Burke Holland Date: Tue, 20 Jan 2026 18:19:39 -0600 Subject: [PATCH 2/2] Clear timeout immedatel instead of in finally --- nodejs/src/session.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nodejs/src/session.ts b/nodejs/src/session.ts index 26fc44a..bc5080f 100644 --- a/nodejs/src/session.ts +++ b/nodejs/src/session.ts @@ -161,10 +161,14 @@ export class CopilotSession { ); }); - await Promise.race([idlePromise, timeoutPromise]); + try { + await Promise.race([idlePromise, timeoutPromise]); + } finally { + // Clear timeout immediately after race completes to prevent memory leaks + if (timeoutId) clearTimeout(timeoutId); + } return lastAssistantMessage; } finally { - if (timeoutId) clearTimeout(timeoutId); unsubscribe(); } }