Skip to content

Commit 9f525c7

Browse files
authored
Merge pull request #203 from gadget-inc/forward-signal-to-child-process
forward the kill signal received by the parent to the child process
2 parents 3f9333d + 8288be2 commit 9f525c7

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wds",
3-
"version": "0.22.0",
3+
"version": "0.23.0",
44
"author": "Harry Brundage",
55
"license": "MIT",
66
"bin": {

src/Project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export class Project {
6161
this.supervisor.restart();
6262
}
6363

64-
async shutdown(code = 0) {
65-
await this.supervisor.stop();
64+
async shutdown(code: number, signal: NodeJS.Signals = "SIGTERM") {
65+
await this.supervisor.stop(signal);
6666
for (const cleanup of this.cleanups) {
6767
cleanup();
6868
}

src/Supervisor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export class Supervisor extends EventEmitter {
1414
}
1515

1616
/**
17-
* Stop the process with a graceful SIGTERM, then SIGKILL after a timeout
17+
* Stop the process with a given signal, then SIGKILL after a timeout
1818
* Kills the whole process group so that any subprocesses of the process are also killed
1919
* See https://azimi.me/2014/12/31/kill-child_process-node-js.html for more information
2020
*/
21-
async stop() {
21+
async stop(signal: NodeJS.Signals = "SIGTERM") {
2222
// if we never started the child process, we don't need to do anything
2323
if (!this.process || !this.process.pid) return;
2424

@@ -27,15 +27,15 @@ export class Supervisor extends EventEmitter {
2727

2828
const ref = this.process;
2929
const exit = once(ref, "exit");
30-
this.kill("SIGTERM");
30+
this.kill(signal);
3131

3232
await Promise.race([exit, setTimeout(5000)]);
3333
if (!ref.killed) {
3434
this.kill("SIGKILL", ref.pid);
3535
}
3636
}
3737

38-
kill(signal = "SIGKILL", pid = this.process?.pid) {
38+
kill(signal: NodeJS.Signals = "SIGKILL", pid = this.process?.pid) {
3939
if (pid) {
4040
try {
4141
process.kill(-pid, signal);

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ export const wds = async (options: RunOptions) => {
197197

198198
process.on("SIGINT", () => {
199199
log.debug(`process ${process.pid} got SIGINT`);
200-
void project.shutdown(0);
200+
void project.shutdown(0, "SIGINT");
201201
});
202202
process.on("SIGTERM", () => {
203203
log.debug(`process ${process.pid} got SIGTERM`);
204-
void project.shutdown(0);
204+
void project.shutdown(0, "SIGTERM");
205205
});
206206

207207
project.supervisor.process.on("exit", (code, signal) => {

0 commit comments

Comments
 (0)