Vite does not shutdown properly when calling close() on the ViteDevServer
Closed this issue · 5 comments
Describe the bug
I would expect after running this script that the process would end:
import { createServer } from 'vite'
const viteServer = await createServer()
await viteServer.close()
This is problematic when using the ViteDevServer with Jest as the process doesn't end cleanly after the server is closed.
This was the commit that introduced the issue: 5999444
Reproduction
This was introduced in Vite 2.4.0-beta.0
https://github.com/schalk-b/vite-not-shutting-down
System Info
System:
OS: Windows 10 10.0.19041
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 16.06 GB / 31.92 GB
Binaries:
Node: 16.4.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.10 - C:\Program Files\nodejs\yarn.CMD
npm: 7.19.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1023.0), Chromium (91.0.864.59)
Internet Explorer: 11.0.19041.1
npmPackages:
vite: ^2.4.0-beta.0 => 2.4.0-beta.3
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
I've taken a look, and I guess I don't see where a call to process.exit()
should happen when calling close()
. If anything, the new behavior seems more correct, and it should be up to the overall parent process to determine when to end the process. In your reproduction, calling process.exit()
after closing the server does end the process.
Edit: I'm still taking a look into this, because I'm not super-familiar with node.js conventions and expectations.
It seems to be the addition of process.stdin.resume()
that causes this issue. I think it can be removed without too much trouble. I put it in because a previous attempt had been made to add it.
Yup that resolves it, thank you
I've taken a look, and I guess I don't see where a call to
process.exit()
should happen when callingclose()
. If anything, the new behavior seems more correct, and it should be up to the overall parent process to determine when to end the process. In your reproduction, callingprocess.exit()
after closing the server does end the process.Edit: I'm still taking a look into this, because I'm not super-familiar with node.js conventions and expectations.
It shouldn't be necessary for a node process to call process.exit() for the process to end. If everything has been "cleaned up" and stopped. The process should end by itself.