-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: prevent rpc timeout on slow thread blocking synchronous methods #8297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sheremet-va
merged 4 commits into
vitest-dev:main
from
AriPerkkio:fix/rpc-timeout-ignore
Jul 22, 2025
Merged
fix: prevent rpc timeout on slow thread blocking synchronous methods #8297
sheremet-va
merged 4 commits into
vitest-dev:main
from
AriPerkkio:fix/rpc-timeout-ignore
Jul 22, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AriPerkkio
commented
Jul 13, 2025
✅ Deploy Preview for vitest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
AriPerkkio
commented
Jul 13, 2025
Worker side error can be tested locally with following changes: diff --git a/packages/vitest/src/node/pools/rpc.ts b/packages/vitest/src/node/pools/rpc.ts
index 351043ad2..7d69b3bb3 100644
--- a/packages/vitest/src/node/pools/rpc.ts
+++ b/packages/vitest/src/node/pools/rpc.ts
@@ -92,6 +92,9 @@ export function createMethodsRPC(project: TestProject, options: MethodsOptions =
async onTaskAnnotate(testId, annotation) {
return ctx._testRun.annotate(testId, annotation)
},
+ async exampleMethodThatsStuck() {
+ await new Promise((resolve) => {})
+ },
async onTaskUpdate(packs, events) {
if (options.collect) {
ctx.state.updateTasks(packs)
diff --git a/packages/vitest/src/runtime/runners/index.ts b/packages/vitest/src/runtime/runners/index.ts
index 26d91a2a2..d5ef6f1c9 100644
--- a/packages/vitest/src/runtime/runners/index.ts
+++ b/packages/vitest/src/runtime/runners/index.ts
@@ -101,6 +101,7 @@ export async function resolveTestRunner(
testRunner.onAfterRunFiles = async (files) => {
const state = getWorkerState()
const coverage = await takeCoverageInsideWorker(config.coverage, executor)
+ rpc().exampleMethodThatsStuck()
if (coverage) {
rpc().onAfterSuiteRun({
diff --git a/packages/vitest/src/types/rpc.ts b/packages/vitest/src/types/rpc.ts
index f6fd773e8..dc5447322 100644
--- a/packages/vitest/src/types/rpc.ts
+++ b/packages/vitest/src/types/rpc.ts
@@ -32,6 +32,8 @@ export interface RuntimeRPC {
onCancel: (reason: CancelReason) => void
getCountOfFailedTests: () => number
+ exampleMethodThatsStuck: () => void
+
snapshotSaved: (snapshot: SnapshotResult) => void
resolveSnapshotPath: (testPath: string) => string
} RUN v4.0.0-beta.2 /x/examples/packages/vitest-example
✓ test/add.test.ts (1 test) 1ms
✓ example 0ms
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: [vitest-worker]: Closing rpc while "exampleMethodThatsStuck" was pending
❯ ../../../vitest/packages/vitest/src/runtime/worker.ts:79:16
❯ ../../../birpc/dist/index.mjs:97:27
❯ Proxy.rejectPendingCalls ../../../birpc/dist/index.mjs:96:19
❯ ../../../vitest/packages/vitest/src/runtime/worker.ts:78:29
❯ ../../../vitest/packages/vitest/src/runtime/worker.ts:120:42
❯ execute ../../../vitest/packages/vitest/src/runtime/worker.ts:120:32
❯ onMessage ../../../vitest/node_modules/.pnpm/tinypool@1.1.1/node_modules/tinypool/dist/entry/process.js:39:18
This error originated in "test/add.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
This error was caught after test environment was torn down. Make sure to cancel any running tasks before test finishes:
- cancel timeouts using clearTimeout and clearInterval
- wait for promises to resolve using the await keyword
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Test Files 1 passed (1)
Tests 1 passed (1)
Errors 1 error
Start at 09:55:52
Duration 200ms (transform 15ms, setup 0ms, collect 15ms, tests 1ms, environment 0ms, prepare 36ms) |
d232fee
to
935a6ea
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Error: [vitest-worker]: Timeout calling "onTaskUpdate"
#8164Ref:
$close
to set original error in.cause
antfu/birpc#25$rejectPendingCalls
antfu/birpc#26Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.