-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from gadget-inc/parent-crash-monitoring
Make zombie children clean themselves up
- Loading branch information
Showing
27 changed files
with
334 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "parent-crash", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
process.stderr.write("child started\n") | ||
setInterval(() => { | ||
process.stderr.write("child still alive\n") | ||
}, 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env zx | ||
const assert = require("assert"); | ||
const { exec } = require("child_process"); | ||
|
||
async function getChildPids(parentPid, callback) { | ||
const result = await $`pgrep -P ${parentPid}`; | ||
return result.stdout | ||
.split("\n") | ||
.filter((pid) => pid) | ||
.map((pid) => parseInt(pid, 10)); | ||
} | ||
|
||
function processIsRunning(pid) { | ||
try { | ||
process.kill(pid, 0); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
const { setTimeout } = require("timers/promises"); | ||
|
||
const main = async () => { | ||
// launch the wds process | ||
const parent = $`${__dirname}/../../pkg/wds.bin.js --watch ${__dirname}/run.ts`.nothrow(); | ||
|
||
// wait for the wds process to start | ||
await setTimeout(500); | ||
|
||
// get the pid of the child process that the parent wds supervisor will have started | ||
const pids = await getChildPids(parent.child.pid); | ||
assert(pids.length > 0, "no child pids found for supervisor process"); | ||
|
||
// SIGKILL the parent process, as if it OOMed or something like that to simulate a zombie child | ||
console.log(`killing parent (${parent.child.pid})`); | ||
await parent.kill(9); | ||
assert.ok(processIsRunning(pids[0]), "test is broken, child process is not running immediately after parent is dead"); | ||
|
||
// ensure the children are dead too after their monitoring delay | ||
await setTimeout(3000); | ||
|
||
for (const pid of pids) { | ||
assert.ok(!processIsRunning(pid), `child process ${pid} is still running after parent has been killed`); | ||
} | ||
|
||
await parent; | ||
}; | ||
|
||
void main(); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const http = require("http"); | ||
|
||
const requestListener = function (req, res) { | ||
res.writeHead(200); | ||
res.end("Hey, Pluto!"); | ||
}; | ||
|
||
const server = http.createServer(requestListener); | ||
server.listen(8080); | ||
console.warn("Listening on 8080"); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.