Skip to content

Commit

Permalink
fix(dev): wait until app server is killed before starting a new app s…
Browse files Browse the repository at this point in the history
…erver (#6289)
  • Loading branch information
pcattori committed May 3, 2023
1 parent 0e2763f commit 16cfda8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-laws-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

wait until app server is killed before starting a new app server
12 changes: 7 additions & 5 deletions packages/remix-dev/devServer_unstable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,15 @@ let relativePath = (file: string) => path.relative(process.cwd(), file);

let kill = async (p?: execa.ExecaChildProcess) => {
if (p === undefined) return;
// `execa`'s `kill` is not reliable on windows
let channel = Channel.create<void>();
p.on("exit", channel.ok);

// https://github.com/nodejs/node/issues/12378
if (process.platform === "win32") {
await execa("taskkill", ["/pid", String(p.pid), "/f", "/t"]);
return;
} else {
p.kill("SIGTERM", { forceKillAfterTimeout: 1_000 });
}

// wait one tick of the event loop so that we guarantee app server gets killed before proceeding
p.kill("SIGTERM", { forceKillAfterTimeout: 0 });
await new Promise((resolve) => setTimeout(resolve, 0));
await channel.result;
};

0 comments on commit 16cfda8

Please sign in to comment.