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

Gracefully shutdown preview server when receiving SIGTERM #12990

Closed
4 tasks done
ambirdsall opened this issue Apr 24, 2023 · 2 comments · Fixed by #17333
Closed
4 tasks done

Gracefully shutdown preview server when receiving SIGTERM #12990

ambirdsall opened this issue Apr 24, 2023 · 2 comments · Fixed by #17333

Comments

@ambirdsall
Copy link

Description

This is closely related to a now-closed past issue and its fix.

I'm working on an app, built with vite, and wish to run a subset of end-to-end Cypress tests on the optimized build. To generate the UI under test, I run vite build followed by vite preview via the start-server-and-test npm package. The issue is that when a test run finishes and the preview server process is ended, it unconditionally ends with an error code, which causes the test run as a whole to be considered failing regardless of the test results. In contrast, running tests against a dev server started with the vite command exhibits the desired behavior: the signal is explicitly caught and the server process is shut down cleanly. Happy to provide a minimal reproduction if that would be useful.

Suggested solution

An interrupt handler like the one in src/node/server/index.ts:

exitProcess = async () => {
  try {
    await server.close()
  } finally {
    process.exit()
  }
}

process.once('SIGTERM', exitProcess)

should be placed in src/node/preview.ts. Perhaps in the httpServerStart function?

Alternative

No response

Additional context

No response

Validations

@perakerberg
Copy link

Experiencing the same issues using playwright tests, causing the process to exit with code 1 and failing the test run.
This fix would be much appreciated. Thanks!

@dbousamra
Copy link

Also experiencing issue. Causing an issue when running using lerna.

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.

4 participants