Skip to content

Commit

Permalink
fix(dev): remove process listeners on server close (#2619)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Mar 23, 2021
1 parent 23f57ee commit 74b360b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ export async function createServer(
const moduleGraph = new ModuleGraph(container)
const closeHttpServer = createServerCloseFn(httpServer)

let exitProcess: () => void

const server: ViteDevServer = {
config: config,
middlewares,
Expand Down Expand Up @@ -324,6 +326,12 @@ export async function createServer(
return startServer(server, port, isRestart)
},
async close() {
process.off('SIGTERM', exitProcess)

if (!process.stdin.isTTY) {
process.stdin.off('end', exitProcess)
}

await Promise.all([
watcher.close(),
ws.close(),
Expand All @@ -341,7 +349,7 @@ export async function createServer(

server.transformIndexHtml = createDevHtmlTransformFn(server)

const exitProcess = async () => {
exitProcess = async () => {
try {
await server.close()
} finally {
Expand Down

0 comments on commit 74b360b

Please sign in to comment.