Skip to content

Commit

Permalink
Switch back to using sigterm so that processes can tear down cleanly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
amcasey committed Oct 4, 2022
1 parent c1fd3d7 commit f694388
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils/execUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ function killTree(childProcess: cp.ChildProcessWithoutNullStreams): Promise<void

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

strictDescendentPids.forEach(pid => process.kill(pid, "SIGKILL"));
childProcess.kill("SIGKILL");
strictDescendentPids.forEach(pid => process.kill(pid));
childProcess.kill();
// Resolve when we detect that childProcess has closed (above)
});
});
Expand Down
9 changes: 9 additions & 0 deletions src/utils/exerciseServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ async function exerciseServerWorker(testDir: string, tsserverPath: string, repla
"--expose-gc",
]);

// You can only wait for kill if the process being killed is the current process's
// child, so it's helpful to our caller if we tear down the server.
process.once("SIGTERM", async () => {
exitExpected = true; // Shouldn't matter, but might as well
await server.kill();
// This is a sneaky way to invoke node's default SIGTERM handler
process.kill(process.pid, "SIGTERM");
});

let loadedNewProject = false;
server.on("event", async (e: any) => {
switch (e.event) {
Expand Down

0 comments on commit f694388

Please sign in to comment.