Skip to content

Commit 9a0c93d

Browse files
authored
fix(browser): stop the browser rpc when the pool is closed (#6858)
1 parent 251893b commit 9a0c93d

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

packages/browser/src/node/pool.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ export function createBrowserPool(ctx: Vitest): ProcessPool {
8686
[...files.map(f => relative(project.config.root, f))].join(', '),
8787
)
8888
const promise = waitForTests(method, contextId, project, files)
89-
promises.push(promise)
90-
orchestrator.createTesters(files)
89+
const tester = orchestrator.createTesters(files).catch((error) => {
90+
if (error instanceof Error && error.message.startsWith('[birpc] rpc is closed')) {
91+
return
92+
}
93+
return Promise.reject(error)
94+
})
95+
promises.push(promise, tester)
9196
}
9297
else {
9398
const contextId = crypto.randomUUID()
@@ -156,6 +161,11 @@ export function createBrowserPool(ctx: Vitest): ProcessPool {
156161
async close() {
157162
await Promise.all([...providers].map(provider => provider.close()))
158163
providers.clear()
164+
ctx.resolvedProjects.forEach((project) => {
165+
project.browser?.state.orchestrators.forEach((orchestrator) => {
166+
orchestrator.$close()
167+
})
168+
})
159169
},
160170
runTests: files => runWorkspaceTests('run', files),
161171
collectTests: files => runWorkspaceTests('collect', files),

packages/vitest/src/node/core.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export class Vitest {
7777

7878
private coreWorkspaceProject!: WorkspaceProject
7979

80-
private resolvedProjects: WorkspaceProject[] = []
80+
/** @private */
81+
public resolvedProjects: WorkspaceProject[] = []
8182
public projects: WorkspaceProject[] = []
8283

8384
public distPath = distDir

packages/vitest/src/node/types/browser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ export interface BrowserServerStateContext {
194194
export interface BrowserOrchestrator {
195195
createTesters: (files: string[]) => Promise<void>
196196
onCancel: (reason: CancelReason) => Promise<void>
197+
$close: () => void
197198
}
198199

199200
export interface BrowserServerState {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy