Skip to content

Commit 658952f

Browse files
committed
graceful closure through abort contorller
1 parent ff67af7 commit 658952f

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/client/stdio.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export class StdioClientTransport implements Transport {
192192
}
193193
}
194194

195-
private async forceExitProcess(pid: number): Promise<void> {
195+
private forceExitProcess(pid: number): void {
196196
try {
197197
process.kill(pid, "SIGKILL");
198198

@@ -206,18 +206,10 @@ export class StdioClientTransport implements Transport {
206206
}
207207
}
208208

209-
private async gracefullyExitProcess(pid: number): Promise<void> {
210-
process.kill(pid, "SIGINT");
211-
212-
await new Promise<void>(resolve => setTimeout(() => {
213-
this.forceExitProcess(pid);
214-
resolve();
215-
}, 3000));
216-
}
217-
218209
async close(): Promise<void> {
210+
const pid = this.pid;
211+
this._abortController.signal.onabort = () => setTimeout(() => pid && this.forceExitProcess(pid), 3000);
219212
this._abortController.abort();
220-
this.gracefullyExitProcess(this.pid!);
221213
this._process = undefined;
222214
this._readBuffer.clear();
223215
}

0 commit comments

Comments
 (0)