Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions nodejs/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ export class CopilotSession {
}
});

let timeoutId: NodeJS.Timeout | undefined;
try {
await this.send(options);

const timeoutPromise = new Promise<never>((_, reject) => {
setTimeout(
timeoutId = setTimeout(
() =>
reject(
new Error(
Expand All @@ -159,8 +160,13 @@ export class CopilotSession {
effectiveTimeout
);
});
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 {
unsubscribe();
Expand Down
Loading