Skip to content

Commit 573dc06

Browse files
authored
fix(worker): rpc listener leak when isolate: false (#8821)
1 parent f393112 commit 573dc06

File tree

1 file changed

+9
-0
lines changed
  • packages/vitest/src/runtime

1 file changed

+9
-0
lines changed

packages/vitest/src/runtime/rpc.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,19 @@ export async function rpcDone(): Promise<unknown[] | undefined> {
6161
return Promise.all(awaitable)
6262
}
6363

64+
let previousRpc: undefined | WorkerRPC
65+
6466
export function createRuntimeRpc(
6567
options: Pick<
6668
BirpcOptions<RuntimeRPC>,
6769
'on' | 'post' | 'serialize' | 'deserialize'
6870
>,
6971
): { rpc: WorkerRPC; onCancel: Promise<CancelReason> } {
72+
if (previousRpc) {
73+
previousRpc.$close()
74+
previousRpc = undefined
75+
}
76+
7077
let setCancel = (_reason: CancelReason) => {}
7178
const onCancel = new Promise<CancelReason>((resolve) => {
7279
setCancel = resolve
@@ -89,6 +96,8 @@ export function createRuntimeRpc(
8996
),
9097
)
9198

99+
previousRpc = rpc
100+
92101
return {
93102
rpc,
94103
onCancel,

0 commit comments

Comments
 (0)