Skip to content

Commit

Permalink
fix: close the rpc when the affected process is closed (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Oct 8, 2024
1 parent 5d59afc commit 5e35243
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ export class VitestFolderAPI {
log.error('[API]', 'Failed to close Vitest process', err)
})
}
this.meta.rpc.$close()
}

async cancelRun() {
Expand Down
5 changes: 5 additions & 0 deletions src/api/child_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ export async function createVitestProcess(pkg: VitestPackage): Promise<ResolvedM
send: message => 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),
Expand Down
4 changes: 4 additions & 0 deletions src/api/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5e35243

Please sign in to comment.