zombie process handler

This commit is contained in:
Thomas Hobson 2021-04-26 13:00:34 +12:00
parent 347f2d56d7
commit 3673b4e403
No known key found for this signature in database
GPG Key ID: 9F1FD9D87950DB6F
4 changed files with 32 additions and 733 deletions

View File

@ -1,4 +1,4 @@
FROM node:15.8.0-buster-slim
FROM node:15.10.0-buster-slim
ENV DEBIAN_FRONTEND=noninteractive
@ -10,16 +10,14 @@ RUN for i in $(seq 1001 1500); do \
RUN apt-get update && \
apt-get install -y libxml2 gnupg tar coreutils util-linux libc6-dev \
binutils build-essential locales libpcre3-dev libevent-dev libgmp3-dev \
libncurses6 libncurses5 libedit-dev libseccomp-dev rename procps && \
libncurses6 libncurses5 libedit-dev libseccomp-dev rename procps python3 && \
rm -rf /var/lib/apt/lists/*
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV NODE_ENV=production
WORKDIR /piston_api
COPY ["package.json", "package-lock.json", "./"]
RUN npm i
RUN npm install
COPY ./src ./src
RUN make -C ./src/nosocket/ all && make -C ./src/nosocket/ install

732
api/package-lock.json generated
View File

@ -266,6 +266,14 @@
"argparse": "^2.0.1"
}
},
"libsys": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/libsys/-/libsys-3.0.0.tgz",
"integrity": "sha512-+c1HMLbV9dIGHfVcjs0PDme9di1CopZ+oL4xqi7LGjeHJfvTsSUAlJtvcfqTkN9wak4WU4cjhLiG1iZwPY1IBw==",
"requires": {
"nan": "^2.14.0"
}
},
"logplease": {
"version": "1.2.15",
"resolved": "https://registry.npmjs.org/logplease/-/logplease-1.2.15.tgz",
@ -317,6 +325,11 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"nan": {
"version": "2.14.2",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz",
"integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ=="
},
"negotiator": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
@ -507,722 +520,9 @@
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
},
"waitpid2": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/waitpid2/-/waitpid2-2.0.5.tgz",
"integrity": "sha1-Yoc+GfCaB69xB0WxcBV8baNLnFU=",
"requires": {
"node-pre-gyp": "^0.6.33"
},
"dependencies": {
"abbrev": {
"version": "1.1.0",
"bundled": true
},
"ajv": {
"version": "4.11.5",
"bundled": true,
"requires": {
"co": "^4.6.0",
"json-stable-stringify": "^1.0.1"
}
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true
},
"aproba": {
"version": "1.1.1",
"bundled": true
},
"are-we-there-yet": {
"version": "1.1.2",
"bundled": true,
"requires": {
"delegates": "^1.0.0",
"readable-stream": "^2.0.0 || ^1.1.13"
}
},
"asn1": {
"version": "0.2.3",
"bundled": true
},
"assert-plus": {
"version": "0.2.0",
"bundled": true
},
"asynckit": {
"version": "0.4.0",
"bundled": true
},
"aws-sign2": {
"version": "0.6.0",
"bundled": true
},
"aws4": {
"version": "1.6.0",
"bundled": true
},
"balanced-match": {
"version": "0.4.2",
"bundled": true
},
"bcrypt-pbkdf": {
"version": "1.0.1",
"bundled": true,
"optional": true,
"requires": {
"tweetnacl": "^0.14.3"
}
},
"block-stream": {
"version": "0.0.9",
"bundled": true,
"requires": {
"inherits": "~2.0.0"
}
},
"boom": {
"version": "2.10.1",
"bundled": true,
"requires": {
"hoek": "2.x.x"
}
},
"brace-expansion": {
"version": "1.1.6",
"bundled": true,
"requires": {
"balanced-match": "^0.4.1",
"concat-map": "0.0.1"
}
},
"buffer-shims": {
"version": "1.0.0",
"bundled": true
},
"caseless": {
"version": "0.12.0",
"bundled": true
},
"co": {
"version": "4.6.0",
"bundled": true
},
"code-point-at": {
"version": "1.1.0",
"bundled": true
},
"combined-stream": {
"version": "1.0.5",
"bundled": true,
"requires": {
"delayed-stream": "~1.0.0"
}
},
"concat-map": {
"version": "0.0.1",
"bundled": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true
},
"core-util-is": {
"version": "1.0.2",
"bundled": true
},
"cryptiles": {
"version": "2.0.5",
"bundled": true,
"requires": {
"boom": "2.x.x"
}
},
"dashdash": {
"version": "1.14.1",
"bundled": true,
"requires": {
"assert-plus": "^1.0.0"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true
}
}
},
"debug": {
"version": "2.2.0",
"bundled": true,
"requires": {
"ms": "0.7.1"
}
},
"deep-extend": {
"version": "0.4.1",
"bundled": true
},
"delayed-stream": {
"version": "1.0.0",
"bundled": true
},
"delegates": {
"version": "1.0.0",
"bundled": true
},
"ecc-jsbn": {
"version": "0.1.1",
"bundled": true,
"optional": true,
"requires": {
"jsbn": "~0.1.0"
}
},
"extend": {
"version": "3.0.0",
"bundled": true
},
"extsprintf": {
"version": "1.0.2",
"bundled": true
},
"forever-agent": {
"version": "0.6.1",
"bundled": true
},
"form-data": {
"version": "2.1.2",
"bundled": true,
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.5",
"mime-types": "^2.1.12"
}
},
"fs.realpath": {
"version": "1.0.0",
"bundled": true
},
"fstream": {
"version": "1.0.11",
"bundled": true,
"requires": {
"graceful-fs": "^4.1.2",
"inherits": "~2.0.0",
"mkdirp": ">=0.5 0",
"rimraf": "2"
}
},
"fstream-ignore": {
"version": "1.0.5",
"bundled": true,
"requires": {
"fstream": "^1.0.0",
"inherits": "2",
"minimatch": "^3.0.0"
}
},
"gauge": {
"version": "2.7.3",
"bundled": true,
"requires": {
"aproba": "^1.0.3",
"console-control-strings": "^1.0.0",
"has-unicode": "^2.0.0",
"object-assign": "^4.1.0",
"signal-exit": "^3.0.0",
"string-width": "^1.0.1",
"strip-ansi": "^3.0.1",
"wide-align": "^1.1.0"
}
},
"getpass": {
"version": "0.1.6",
"bundled": true,
"requires": {
"assert-plus": "^1.0.0"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true
}
}
},
"glob": {
"version": "7.1.1",
"bundled": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.2",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"graceful-fs": {
"version": "4.1.11",
"bundled": true
},
"har-schema": {
"version": "1.0.5",
"bundled": true
},
"har-validator": {
"version": "4.2.1",
"bundled": true,
"requires": {
"ajv": "^4.9.1",
"har-schema": "^1.0.5"
}
},
"has-unicode": {
"version": "2.0.1",
"bundled": true
},
"hawk": {
"version": "3.1.3",
"bundled": true,
"requires": {
"boom": "2.x.x",
"cryptiles": "2.x.x",
"hoek": "2.x.x",
"sntp": "1.x.x"
}
},
"hoek": {
"version": "2.16.3",
"bundled": true
},
"http-signature": {
"version": "1.1.1",
"bundled": true,
"requires": {
"assert-plus": "^0.2.0",
"jsprim": "^1.2.2",
"sshpk": "^1.7.0"
}
},
"inflight": {
"version": "1.0.6",
"bundled": true,
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.3",
"bundled": true
},
"ini": {
"version": "1.3.4",
"bundled": true
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"requires": {
"number-is-nan": "^1.0.0"
}
},
"is-typedarray": {
"version": "1.0.0",
"bundled": true
},
"isarray": {
"version": "1.0.0",
"bundled": true
},
"isstream": {
"version": "0.1.2",
"bundled": true
},
"jodid25519": {
"version": "1.0.2",
"bundled": true,
"optional": true,
"requires": {
"jsbn": "~0.1.0"
}
},
"jsbn": {
"version": "0.1.1",
"bundled": true,
"optional": true
},
"json-schema": {
"version": "0.2.3",
"bundled": true
},
"json-stable-stringify": {
"version": "1.0.1",
"bundled": true,
"requires": {
"jsonify": "~0.0.0"
}
},
"json-stringify-safe": {
"version": "5.0.1",
"bundled": true
},
"jsonify": {
"version": "0.0.0",
"bundled": true
},
"jsprim": {
"version": "1.4.0",
"bundled": true,
"requires": {
"assert-plus": "1.0.0",
"extsprintf": "1.0.2",
"json-schema": "0.2.3",
"verror": "1.3.6"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true
}
}
},
"mime-db": {
"version": "1.26.0",
"bundled": true
},
"mime-types": {
"version": "2.1.14",
"bundled": true,
"requires": {
"mime-db": "~1.26.0"
}
},
"minimatch": {
"version": "3.0.3",
"bundled": true,
"requires": {
"brace-expansion": "^1.0.0"
}
},
"minimist": {
"version": "0.0.8",
"bundled": true
},
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"requires": {
"minimist": "0.0.8"
}
},
"ms": {
"version": "0.7.1",
"bundled": true
},
"node-pre-gyp": {
"version": "0.6.33",
"bundled": true,
"requires": {
"mkdirp": "~0.5.1",
"nopt": "~3.0.6",
"npmlog": "^4.0.1",
"rc": "~1.1.6",
"request": "^2.79.0",
"rimraf": "~2.5.4",
"semver": "~5.3.0",
"tar": "~2.2.1",
"tar-pack": "~3.3.0"
}
},
"nopt": {
"version": "3.0.6",
"bundled": true,
"requires": {
"abbrev": "1"
}
},
"npmlog": {
"version": "4.0.2",
"bundled": true,
"requires": {
"are-we-there-yet": "~1.1.2",
"console-control-strings": "~1.1.0",
"gauge": "~2.7.1",
"set-blocking": "~2.0.0"
}
},
"number-is-nan": {
"version": "1.0.1",
"bundled": true
},
"oauth-sign": {
"version": "0.8.2",
"bundled": true
},
"object-assign": {
"version": "4.1.1",
"bundled": true
},
"once": {
"version": "1.4.0",
"bundled": true,
"requires": {
"wrappy": "1"
}
},
"path-is-absolute": {
"version": "1.0.1",
"bundled": true
},
"performance-now": {
"version": "0.2.0",
"bundled": true
},
"process-nextick-args": {
"version": "1.0.7",
"bundled": true
},
"punycode": {
"version": "1.4.1",
"bundled": true
},
"qs": {
"version": "6.4.0",
"bundled": true
},
"rc": {
"version": "1.1.7",
"bundled": true,
"requires": {
"deep-extend": "~0.4.0",
"ini": "~1.3.0",
"minimist": "^1.2.0",
"strip-json-comments": "~2.0.1"
},
"dependencies": {
"minimist": {
"version": "1.2.0",
"bundled": true
}
}
},
"readable-stream": {
"version": "2.2.5",
"bundled": true,
"requires": {
"buffer-shims": "^1.0.0",
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "~1.0.0",
"process-nextick-args": "~1.0.6",
"string_decoder": "~0.10.x",
"util-deprecate": "~1.0.1"
}
},
"request": {
"version": "2.81.0",
"bundled": true,
"requires": {
"aws-sign2": "~0.6.0",
"aws4": "^1.2.1",
"caseless": "~0.12.0",
"combined-stream": "~1.0.5",
"extend": "~3.0.0",
"forever-agent": "~0.6.1",
"form-data": "~2.1.1",
"har-validator": "~4.2.1",
"hawk": "~3.1.3",
"http-signature": "~1.1.0",
"is-typedarray": "~1.0.0",
"isstream": "~0.1.2",
"json-stringify-safe": "~5.0.1",
"mime-types": "~2.1.7",
"oauth-sign": "~0.8.1",
"performance-now": "^0.2.0",
"qs": "~6.4.0",
"safe-buffer": "^5.0.1",
"stringstream": "~0.0.4",
"tough-cookie": "~2.3.0",
"tunnel-agent": "^0.6.0",
"uuid": "^3.0.0"
}
},
"rimraf": {
"version": "2.5.4",
"bundled": true,
"requires": {
"glob": "^7.0.5"
}
},
"safe-buffer": {
"version": "5.0.1",
"bundled": true
},
"semver": {
"version": "5.3.0",
"bundled": true
},
"set-blocking": {
"version": "2.0.0",
"bundled": true
},
"signal-exit": {
"version": "3.0.2",
"bundled": true
},
"sntp": {
"version": "1.0.9",
"bundled": true,
"requires": {
"hoek": "2.x.x"
}
},
"sshpk": {
"version": "1.11.0",
"bundled": true,
"requires": {
"asn1": "~0.2.3",
"assert-plus": "^1.0.0",
"bcrypt-pbkdf": "^1.0.0",
"dashdash": "^1.12.0",
"ecc-jsbn": "~0.1.1",
"getpass": "^0.1.1",
"jodid25519": "^1.0.0",
"jsbn": "~0.1.0",
"tweetnacl": "~0.14.0"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true
}
}
},
"string-width": {
"version": "1.0.2",
"bundled": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
"strip-ansi": "^3.0.0"
}
},
"string_decoder": {
"version": "0.10.31",
"bundled": true
},
"stringstream": {
"version": "0.0.5",
"bundled": true
},
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"requires": {
"ansi-regex": "^2.0.0"
}
},
"strip-json-comments": {
"version": "2.0.1",
"bundled": true
},
"tar": {
"version": "2.2.1",
"bundled": true,
"requires": {
"block-stream": "*",
"fstream": "^1.0.2",
"inherits": "2"
}
},
"tar-pack": {
"version": "3.3.0",
"bundled": true,
"requires": {
"debug": "~2.2.0",
"fstream": "~1.0.10",
"fstream-ignore": "~1.0.5",
"once": "~1.3.3",
"readable-stream": "~2.1.4",
"rimraf": "~2.5.1",
"tar": "~2.2.1",
"uid-number": "~0.0.6"
},
"dependencies": {
"once": {
"version": "1.3.3",
"bundled": true,
"requires": {
"wrappy": "1"
}
},
"readable-stream": {
"version": "2.1.5",
"bundled": true,
"requires": {
"buffer-shims": "^1.0.0",
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "~1.0.0",
"process-nextick-args": "~1.0.6",
"string_decoder": "~0.10.x",
"util-deprecate": "~1.0.1"
}
}
}
},
"tough-cookie": {
"version": "2.3.2",
"bundled": true,
"requires": {
"punycode": "^1.4.1"
}
},
"tunnel-agent": {
"version": "0.6.0",
"bundled": true,
"requires": {
"safe-buffer": "^5.0.1"
}
},
"tweetnacl": {
"version": "0.14.5",
"bundled": true,
"optional": true
},
"uid-number": {
"version": "0.0.6",
"bundled": true
},
"util-deprecate": {
"version": "1.0.2",
"bundled": true
},
"uuid": {
"version": "3.0.1",
"bundled": true
},
"verror": {
"version": "1.3.6",
"bundled": true,
"requires": {
"extsprintf": "1.0.2"
}
},
"wide-align": {
"version": "1.1.0",
"bundled": true,
"requires": {
"string-width": "^1.0.1"
}
},
"wrappy": {
"version": "1.0.2",
"bundled": true
}
}
"waitpid": {
"version": "git+https://github.com/HexF/node-waitpid.git#a08d116a5d993a747624fe72ff890167be8c34aa",
"from": "git+https://github.com/HexF/node-waitpid.git"
},
"wrap-ansi": {
"version": "7.0.0",

View File

@ -8,14 +8,16 @@
"express": "^4.17.1",
"is-docker": "^2.1.1",
"js-yaml": "^4.0.0",
"libsys": "^3.0.0",
"logplease": "^1.2.15",
"nocamel": "HexF/nocamel#patch-1",
"node-fetch": "^2.6.1",
"ps-list": "^7.2.0",
"semver": "^7.3.4",
"uuid": "^8.3.2",
"waitpid2": "^2.0.5",
"waitpid": "git+https://github.com/HexF/node-waitpid.git",
"yargs": "^16.2.0"
},
"license": "MIT"
}

View File

@ -6,7 +6,7 @@ const config = require('./config');
const globals = require('./globals');
const fs = require('fs/promises');
const ps_list = require('ps-list');
const wait_pid = require('waitpid2');
const wait_pid = require('waitpid');
const job_states = {
READY: Symbol('Ready to be primed'),
@ -185,18 +185,17 @@ class Job {
async cleanup() {
logger.info(`Cleaning up job uuid=${this.uuid}`);
await fs.rm(this.dir, { recursive: true, force: true });
let processes = [1]
while(processes.length > 0){
let processes = await ps_list();
processes.filter(proc => proc.uid == this.uid);
processes = await ps_list();
processes = processes.filter(proc => proc.uid == this.uid);
await Promise.all(
processes.map(
async proc => {
process.kill(proc.pid, 'SIGKILL');
wait_pid(proc.pid, wait_pid.WNOHANG); //Free zombie state process
}
)
);
for(const proc of processes){
process.kill(proc.pid, 'SIGKILL');
wait_pid(proc.pid);
}
}
}