fix: exit server process when daemon is stopped
MODIFY
internal/cli/server.ts
internal/cli/server.ts
@@ -15,6 +15,7 @@ import setProcessTitle from "./utils/setProcessTitle";
import net = require("net");
import {loadUserConfig} from "@internal/core/common/userConfig";
import {isBridgeEndDiagnosticsError} from "@internal/events";
+import {createResourceFromServer} from "@internal/resources";
export default async function server() {
setProcessTitle("server");
@@ -40,6 +41,7 @@ export default async function server() {
}),
);
});
+ server.resources.add(createResourceFromServer(socketServer));
socketServer.on(
"error",

MODIFY
internal/core/client/Client.ts
internal/core/client/Client.ts
@@ -737,6 +737,7 @@ export default class Client {
"server",
{
detached: true,
+ stdio: "ignore",
},
);
proc.unref();

MODIFY
internal/core/server/commands/stop.ts
internal/core/server/commands/stop.ts
@@ -9,6 +9,7 @@ import {ServerRequest} from "@internal/core";
import {commandCategories} from "../../common/commands";
import {createServerCommand} from "../commands";
import {markup} from "@internal/markup";
+import {safeProcessExit} from "@internal/resources";
export default createServerCommand({
category: commandCategories.PROCESS_MANAGEMENT,
@@ -20,5 +21,6 @@ export default createServerCommand({
},
async callback({server}: ServerRequest) {
await server.end();
+ await safeProcessExit(0);
},
});

MODIFY
internal/resources/factories.ts
internal/resources/factories.ts
@@ -142,7 +142,7 @@ export function createResourceFromServer(server: net.Server, name: string = "net
finalize: () => {
return new Promise((resolve, reject) => {
server.close((err) => {
- if (err === undefined) {
+ if (err != null) {
reject(err);
} else {
resolve();

fix: exit server process when daemon is stopped (#1530)