-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: close vite servers on all resolved projects #5544
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
fix: close vite servers on all resolved projects #5544
Conversation
✅ Deploy Preview for fastidious-cascaron-4ded94 canceled.
|
|
Interesting finding! How did you narrow the root cause to the websocket connections? Looks like Vitest's $ npx vitest run --project space_1 --reporter hanging-process --reporter basic
RUN v1.5.0 /Users/x/vitest/test/cli/fixtures/project
✓ |space_1| base.test.ts (1 test) 1ms
Test Files 1 passed (1)
Tests 1 passed (1)
Start at 08:15:25
Duration 147ms (transform 12ms, setup 0ms, collect 6ms, tests 1ms, environment 0ms, prepare 45ms)
There are 12 handle(s) keeping the process running
# Tinypool
node:internal/async_hooks:202
node:internal/async_hooks:504
file:///Users/x/vitest/node_modules/.pnpm/[email protected]/node_modules/tinypool/dist/esm/index.js:37
file:///Users/x/vitest/node_modules/.pnpm/[email protected]/node_modules/tinypool/dist/esm/index.js:58
file:///Users/x/vitest/node_modules/.pnpm/[email protected]/node_modules/tinypool/dist/esm/index.js:945
file:///Users/x/vitest/packages/vitest/dist/vendor/cac.WCfoZ7tE.js:8776
file:///Users/x/vitest/packages/vitest/dist/vendor/cac.WCfoZ7tE.js:9425
file:///Users/x/vitest/packages/vitest/dist/vendor/cac.WCfoZ7tE.js:9450
# FILEHANDLE
node:internal/async_hooks:202
... FILEHANDLE x9 here
# FILEHANDLE
node:internal/async_hooks:202
close timed out after 10000ms
Tests closed successfully but something prevents the main process from exiting
You can try to identify the cause by enabling "hanging-process" reporter. See https://vitest.dev/config/#reportersIt's only reporting |
AriPerkkio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same logic should be used here:
vitest/packages/vitest/src/node/core.ts
Lines 908 to 917 in df6a432
| const runningServers = [this.server, ...this.projects.map(p => p.server)].filter(Boolean).length | |
| if (runningServers === 1) | |
| console.warn('Tests closed successfully but something prevents Vite server from exiting') | |
| else if (runningServers > 1) | |
| console.warn(`Tests closed successfully but something prevents ${runningServers} Vite servers from exiting`) | |
| else | |
| console.warn('Tests closed successfully but something prevents the main process from exiting') | |
| console.warn('You can try to identify the cause by enabling "hanging-process" reporter. See https://vitest.dev/config/#reporters') |
Then the reproduction case would print following:
close timed out after 10000ms
Tests closed successfully but something prevents 2 Vite servers from exiting
65452aa to
4c840e5
Compare
|
@AriPerkkio Thanks for the review! I've updated that location to use As for how I tracked it down, I used a debugger to run The server caught my interest, and upon checking its address, I noticed that it was on port 24678. Searching the vite repository led me to the dev server code. |
Description
I've been running into an issue where Vitest would hang after the testing is completed with the following output:
Luckily, this repo has a reproducible setup at
test/cli/fixtures/project-- in this directory, runningnpx vitest run --project space_1causes the error above (you may need to try multiple times, but I've been getting it consistently).The only other report I've found is by this commenter #2008 (comment) (the issue itself seems to be about a different time out issue).
I've tracked this down to a Vite web-socket server not being cleaned up at the end of the Vitest session.
This PR edits the
Vitest#close()method to close the Vite dev servers on ALL resolved projects instead of just the filtered projects.I tried to write a new test under
test/clibut it seems that the Vite servers for the fixture projects do not get launched due to a port conflict with the Vitest instance running the actual test. I could not find a way to use a different port.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.