Fix some more thread leaks
This commit is contained in:
parent
fb166f4115
commit
964ed080e8
|
@ -50,6 +50,9 @@ export function watchPods() {
|
|||
podExists: (podName) => {
|
||||
return podName in pods;
|
||||
},
|
||||
close: () => {
|
||||
informer.stop();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -361,6 +364,9 @@ export async function initUserSession({ watcher, podName, proxyInfo }) {
|
|||
})
|
||||
),
|
||||
},
|
||||
close: () => {
|
||||
conn.close();
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
@ -60,13 +60,15 @@ async function main() {
|
|||
// pty.
|
||||
const outputQueue = new PQueue({ concurrency: 1, autoStart: false });
|
||||
let handlePtyOutput, handlePtyExit;
|
||||
const exec = await session.exec(["bash"], {
|
||||
let exec = await session.exec(["bash"], {
|
||||
pty: true,
|
||||
on: {
|
||||
stdout: (data) => outputQueue.add(() => handlePtyOutput(data)),
|
||||
stderr: (data) => process.stderr.write(data),
|
||||
exit: (status) => {
|
||||
handlePtyExit();
|
||||
watcher.close();
|
||||
exec.close();
|
||||
process.exit(status);
|
||||
},
|
||||
error: (err) => process.stderr.write(`riju: error: ${err}\n`),
|
||||
|
|
|
@ -187,7 +187,7 @@ export function asBool(value, def) {
|
|||
// cluster.
|
||||
export function deptyify({ handlePtyInput }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const done = false;
|
||||
let done = false;
|
||||
let triggerDone = () => {
|
||||
// Calling the function stored in this variable should have the
|
||||
// effect of terminating the tmp-promise callback and getting
|
||||
|
@ -251,13 +251,18 @@ export function deptyify({ handlePtyInput }) {
|
|||
// SIGTERM, wait for proc to exit, if it doesn't,
|
||||
// then SIGKILL.
|
||||
proc.kill("SIGTERM");
|
||||
let timeout = null;
|
||||
try {
|
||||
await new Promise((resolve, reject) => {
|
||||
proc.on("exit", resolve);
|
||||
setTimeout(reject, 1000);
|
||||
timeout = setTimeout(reject, 250);
|
||||
});
|
||||
} catch (err) {
|
||||
proc.kill("SIGKILL");
|
||||
} finally {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logError(err);
|
||||
|
|
|
@ -95,6 +95,10 @@ int main(int argc, char **argv)
|
|||
if (exec_pid < 0)
|
||||
die("fork failed");
|
||||
else if (exec_pid == 0) {
|
||||
if (signal(SIGTERM, SIG_DFL) == SIG_ERR)
|
||||
die("signal failed");
|
||||
if (signal(SIGINT, SIG_DFL) == SIG_ERR)
|
||||
die("signal failed");
|
||||
if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0)
|
||||
die("prctl failed");
|
||||
if (getppid() != orig_ppid)
|
||||
|
@ -131,6 +135,10 @@ int main(int argc, char **argv)
|
|||
}
|
||||
return WEXITSTATUS(wstatus);
|
||||
}
|
||||
if (signal(SIGTERM, SIG_DFL) == SIG_ERR)
|
||||
die("signal failed");
|
||||
if (signal(SIGINT, SIG_DFL) == SIG_ERR)
|
||||
die("signal failed");
|
||||
if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0)
|
||||
die("prctl failed");
|
||||
if (getppid() != orig_ppid)
|
||||
|
|
Loading…
Reference in New Issue