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

fix(dev): kill app server when remix dev terminates #7280

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-chefs-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

kill app server when remix dev terminates
5 changes: 4 additions & 1 deletion packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ export async function dev(
let config = await readConfig(remixRoot);

let resolved = await resolveDevServe(config, flags);
await devServer_unstable.serve(config, resolved);
devServer_unstable.serve(config, resolved);

// keep `remix dev` alive by waiting indefinitely
await new Promise(() => {});
}

let clientEntries = ["entry.client.tsx", "entry.client.js", "entry.client.jsx"];
Expand Down
11 changes: 7 additions & 4 deletions packages/remix-dev/devServer_unstable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -22,7 +23,7 @@ import type { Result } from "../result";
import { err, ok } from "../result";
import invariant from "../invariant";
import { logger } from "../tux";
import { kill, killtree } from "./proc";
import { killtree } from "./proc";

let detectBin = async (): Promise<string> => {
let pkgManager = detectPackageManager() ?? "npm";
Expand Down Expand Up @@ -267,12 +268,14 @@ export let serve = async (

server.listen(options.port);

return new Promise(() => {}).finally(async () => {
state.appServer?.pid && (await kill(state.appServer.pid));
let cleanup = async () => {
state.appServer?.kill();
websocket.close();
server.close();
await dispose();
});
};
exitHook(cleanup);
return cleanup;
};

let clean = (config: RemixConfig) => {
Expand Down