Skip to content

Commit d84e17d

Browse files
authored
fix: clear timeout timer in sendAndWait to prevent process hang (#349)
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
1 parent ad724d1 commit d84e17d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

nodejs/src/session.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,12 @@ export class CopilotSession {
167167
}
168168
});
169169

170+
let timeoutId: ReturnType<typeof setTimeout> | undefined;
170171
try {
171172
await this.send(options);
172173

173174
const timeoutPromise = new Promise<never>((_, reject) => {
174-
setTimeout(
175+
timeoutId = setTimeout(
175176
() =>
176177
reject(
177178
new Error(
@@ -185,6 +186,9 @@ export class CopilotSession {
185186

186187
return lastAssistantMessage;
187188
} finally {
189+
if (timeoutId !== undefined) {
190+
clearTimeout(timeoutId);
191+
}
188192
unsubscribe();
189193
}
190194
}

0 commit comments

Comments
 (0)