Skip to content
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

Vite does not shutdown properly when calling close() on the ViteDevServer #4079

Closed
6 tasks done
schalk-b opened this issue Jul 2, 2021 · 5 comments · Fixed by #4082
Closed
6 tasks done

Vite does not shutdown properly when calling close() on the ViteDevServer #4079

schalk-b opened this issue Jul 2, 2021 · 5 comments · Fixed by #4082

Comments

@schalk-b
Copy link

schalk-b commented Jul 2, 2021

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

@IanVS
Copy link
Contributor

IanVS commented Jul 2, 2021

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.

@IanVS
Copy link
Contributor

IanVS commented Jul 2, 2021

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.

@schalk-b
Copy link
Author

schalk-b commented Jul 2, 2021

Yup that resolves it, thank you

@schalk-b
Copy link
Author

schalk-b commented Jul 2, 2021

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 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.

@maxbeatty
Copy link

I found my way here debugging vite-jest not working with vite@2.4. It looks like #4082 is close to merging so hopefully a fix can be published soon. In the meantime, using vite@2.3 or setting CI=true (e.g. CI=true vite-jest) seems to work around this.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants