Skip to content

Commit 915d6c4

Browse files
authoredJan 26, 2024
fix(threads): mention common work-around for the logged error (#5024)
1 parent cfd0611 commit 915d6c4

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed
 

‎docs/guide/common-errors.md

+27
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,30 @@ sideEffect()
5858

5959
vi.resetModules()
6060
```
61+
62+
## Failed to terminate worker
63+
64+
This error can happen when NodeJS's `fetch` is used with default [`pool: 'threads'`](/config/#pool-1-0-0). This issue is tracked on issue [Timeout abort can leave process(es) running in the background #3077](https://github.com/vitest-dev/vitest/issues/3077).
65+
66+
As work-around you can switch to [`pool: 'forks'`](/config/#forks) or [`pool: 'vmForks'`](/config/#vmforks).
67+
68+
Specify `pool` in your configuration file:
69+
70+
```ts
71+
import { defineConfig } from 'vitest/config'
72+
73+
export default defineConfig({
74+
test: {
75+
pool: 'forks',
76+
},
77+
})
78+
```
79+
80+
Or in your `package.json` scripts:
81+
82+
```diff
83+
scripts: {
84+
- "test": "vitest"
85+
+ "test": "vitest --pool=forks"
86+
}
87+
```

‎packages/vitest/src/node/pools/threads.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function createThreadsPool(ctx: Vitest, { execArgv, env }: PoolProcessOpt
107107
catch (error) {
108108
// Worker got stuck and won't terminate - this may cause process to hang
109109
if (error instanceof Error && /Failed to terminate worker/.test(error.message))
110-
ctx.state.addProcessTimeoutCause(`Failed to terminate worker while running ${files.join(', ')}.`)
110+
ctx.state.addProcessTimeoutCause(`Failed to terminate worker while running ${files.join(', ')}. \nSee https://vitest.dev/guide/common-errors.html#failed-to-terminate-worker for troubleshooting.`)
111111

112112
// Intentionally cancelled
113113
else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message))

‎packages/vitest/src/node/pools/vmThreads.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function createVmThreadsPool(ctx: Vitest, { execArgv, env }: PoolProcessO
111111
catch (error) {
112112
// Worker got stuck and won't terminate - this may cause process to hang
113113
if (error instanceof Error && /Failed to terminate worker/.test(error.message))
114-
ctx.state.addProcessTimeoutCause(`Failed to terminate worker while running ${files.join(', ')}.`)
114+
ctx.state.addProcessTimeoutCause(`Failed to terminate worker while running ${files.join(', ')}. \nSee https://vitest.dev/guide/common-errors.html#failed-to-terminate-worker for troubleshooting.`)
115115

116116
// Intentionally cancelled
117117
else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message))

0 commit comments

Comments
 (0)
Please sign in to comment.