diff --git a/backend/k8s.js b/backend/k8s.js index b462b6c..58a996e 100644 --- a/backend/k8s.js +++ b/backend/k8s.js @@ -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(); + }, }; }, }); diff --git a/backend/sandbox-k8s.js b/backend/sandbox-k8s.js index effb26a..9dc915f 100644 --- a/backend/sandbox-k8s.js +++ b/backend/sandbox-k8s.js @@ -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`), diff --git a/backend/util.js b/backend/util.js index 9ea428f..f0955d7 100644 --- a/backend/util.js +++ b/backend/util.js @@ -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); diff --git a/system/src/riju-pty.c b/system/src/riju-pty.c index 04459a4..da6df62 100644 --- a/system/src/riju-pty.c +++ b/system/src/riju-pty.c @@ -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)