From 5e352434f9d951b35ea77e639c0a57e1c052e956 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 8 Oct 2024 17:03:29 +0200 Subject: [PATCH] fix: close the rpc when the affected process is closed (#494) --- src/api.ts | 1 - src/api/child_process.ts | 5 +++++ src/api/ws.ts | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index accf0369..6da26658 100644 --- a/src/api.ts +++ b/src/api.ts @@ -174,7 +174,6 @@ export class VitestFolderAPI { log.error('[API]', 'Failed to close Vitest process', err) }) } - this.meta.rpc.$close() } async cancelRun() { diff --git a/src/api/child_process.ts b/src/api/child_process.ts index 68e19096..6a616232 100644 --- a/src/api/child_process.ts +++ b/src/api/child_process.ts @@ -134,6 +134,11 @@ export async function createVitestProcess(pkg: VitestPackage): Promise vitest.send(message), }) + vitest.once('exit', () => { + log.verbose?.('[API]', 'Vitest child_process connection closed, cannot call RPC anymore.') + api.$close() + }) + return { rpc: api, process: new VitestChildProcess(vitest), diff --git a/src/api/ws.ts b/src/api/ws.ts index 86b08837..e6a4a994 100644 --- a/src/api/ws.ts +++ b/src/api/ws.ts @@ -27,6 +27,10 @@ export function waitForWsResolvedMeta( on: listener => ws.on('message', listener), send: message => ws.send(message), }) + ws.once('close', () => { + log.verbose?.('[API]', 'Vitest WebSocket connection closed, cannot call RPC anymore.') + api.$close() + }) resolve({ rpc: api, handlers,