From 55a42a9c92791d8c8eae80b257d47019f066db7b Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Tue, 5 Nov 2024 13:55:56 +0100 Subject: [PATCH] fix(browser): stop the browser rpc when the pool is closed --- packages/browser/src/node/pool.ts | 14 ++++++++++++-- packages/vitest/src/node/core.ts | 3 ++- packages/vitest/src/node/types/browser.ts | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/browser/src/node/pool.ts b/packages/browser/src/node/pool.ts index c0bc9f0f8828..bd7399a42dee 100644 --- a/packages/browser/src/node/pool.ts +++ b/packages/browser/src/node/pool.ts @@ -86,8 +86,13 @@ export function createBrowserPool(ctx: Vitest): ProcessPool { [...files.map(f => relative(project.config.root, f))].join(', '), ) const promise = waitForTests(method, contextId, project, files) - promises.push(promise) - orchestrator.createTesters(files) + const tester = orchestrator.createTesters(files).catch((error) => { + if (error instanceof Error && error.message.startsWith('[birpc] rpc is closed')) { + return + } + return Promise.reject(error) + }) + promises.push(promise, tester) } else { const contextId = crypto.randomUUID() @@ -156,6 +161,11 @@ export function createBrowserPool(ctx: Vitest): ProcessPool { async close() { await Promise.all([...providers].map(provider => provider.close())) providers.clear() + ctx.resolvedProjects.forEach((project) => { + project.browser?.state.orchestrators.forEach((orchestrator) => { + orchestrator.$close() + }) + }) }, runTests: files => runWorkspaceTests('run', files), collectTests: files => runWorkspaceTests('collect', files), diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 763fec4c468a..a060ed87e7d6 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -77,7 +77,8 @@ export class Vitest { private coreWorkspaceProject!: WorkspaceProject - private resolvedProjects: WorkspaceProject[] = [] + /** @private */ + public resolvedProjects: WorkspaceProject[] = [] public projects: WorkspaceProject[] = [] public distPath = distDir diff --git a/packages/vitest/src/node/types/browser.ts b/packages/vitest/src/node/types/browser.ts index 3d607c6dae47..243fdfcbc614 100644 --- a/packages/vitest/src/node/types/browser.ts +++ b/packages/vitest/src/node/types/browser.ts @@ -194,6 +194,7 @@ export interface BrowserServerStateContext { export interface BrowserOrchestrator { createTesters: (files: string[]) => Promise onCancel: (reason: CancelReason) => Promise + $close: () => void } export interface BrowserServerState {