Skip to content

Commit f694388

Browse files
authored
Switch back to using sigterm so that processes can tear down cleanly (microsoft#79)
1 parent c1fd3d7 commit f694388

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/utils/execUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ function killTree(childProcess: cp.ChildProcessWithoutNullStreams): Promise<void
121121

122122
console.log(`Killing process ${childProcessPid} and its descendents: ${strictDescendentPids.join(", ")}`);
123123

124-
strictDescendentPids.forEach(pid => process.kill(pid, "SIGKILL"));
125-
childProcess.kill("SIGKILL");
124+
strictDescendentPids.forEach(pid => process.kill(pid));
125+
childProcess.kill();
126126
// Resolve when we detect that childProcess has closed (above)
127127
});
128128
});

src/utils/exerciseServer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ async function exerciseServerWorker(testDir: string, tsserverPath: string, repla
8787
"--expose-gc",
8888
]);
8989

90+
// You can only wait for kill if the process being killed is the current process's
91+
// child, so it's helpful to our caller if we tear down the server.
92+
process.once("SIGTERM", async () => {
93+
exitExpected = true; // Shouldn't matter, but might as well
94+
await server.kill();
95+
// This is a sneaky way to invoke node's default SIGTERM handler
96+
process.kill(process.pid, "SIGTERM");
97+
});
98+
9099
let loadedNewProject = false;
91100
server.on("event", async (e: any) => {
92101
switch (e.event) {

0 commit comments

Comments
 (0)