From 764e9b1693789f0b6784f2ae848665d9ed82b892 Mon Sep 17 00:00:00 2001 From: Pedro Cattori Date: Mon, 28 Aug 2023 15:27:14 -0400 Subject: [PATCH] fix(dev): kill app server when `remix dev` terminates --- .changeset/olive-chefs-jam.md | 5 +++++ packages/remix-dev/devServer_unstable/index.ts | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 .changeset/olive-chefs-jam.md diff --git a/.changeset/olive-chefs-jam.md b/.changeset/olive-chefs-jam.md new file mode 100644 index 00000000000..168d26cc22f --- /dev/null +++ b/.changeset/olive-chefs-jam.md @@ -0,0 +1,5 @@ +--- +"@remix-run/dev": patch +--- + +kill app server when remix dev terminates diff --git a/packages/remix-dev/devServer_unstable/index.ts b/packages/remix-dev/devServer_unstable/index.ts index e54047b43ef..3aa9ffe4bd1 100644 --- a/packages/remix-dev/devServer_unstable/index.ts +++ b/packages/remix-dev/devServer_unstable/index.ts @@ -7,6 +7,7 @@ import prettyMs from "pretty-ms"; import execa from "execa"; import express from "express"; import pc from "picocolors"; +import exitHook from "exit-hook"; import * as Channel from "../channel"; import { type Manifest } from "../manifest"; @@ -267,6 +268,12 @@ export let serve = async ( server.listen(options.port); + exitHook(() => { + state.appServer?.pid && kill(state.appServer.pid); + websocket.close(); + server.close(); + }); + return new Promise(() => {}).finally(async () => { state.appServer?.pid && (await kill(state.appServer.pid)); websocket.close();