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

Calling close() on a ViteDevServer instance that was never started throws #1855

Closed
ggoodman opened this issue Feb 3, 2021 · 1 comment
Closed

Comments

@ggoodman
Copy link

ggoodman commented Feb 3, 2021

Describe the bug

When using the programmatic SSR API of a ViteDevServer instance in another server, attempting to dispose of the instance via the close method will throw when the http server has not been started.

Reproduction

const Vite = require('vite');

Vite.createServer().then((vite) => {
  vite.close();
});

Will throw an uncaught exception:

Error [ERR_SERVER_NOT_RUNNING]: Server is not running.
    at Server.close (net.js:1606:12)
    at Object.onceWrapper (events.js:421:28)
    at Server.emit (events.js:315:20)
    at emitCloseNT (net.js:1659:8)
    at processTicksAndRejections (internal/process/task_queues.js:79:21)

via

await Promise.all([
watcher.close(),
ws.close(),
container.close(),
closeHttpServer()
])

Perhaps an easy fix would be to add an additional condition on || !server.listening here:

System Info

  • vite version: 2.0.0-beta.62
  • Operating System: MacOS 11.2
  • Node version: v14.15.4
  • Package manager (npm/yarn/pnpm) and version: 6.14.10

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag. N/A
  2. Provide the error log here. See above
@CHOYSEN
Copy link
Contributor

CHOYSEN commented Feb 3, 2021

Perhaps an easy fix would be to add an additional condition on || !server.listening here:

PR Welcome!

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

No branches or pull requests

2 participants