Fix some logic and control flow issues
This commit is contained in:
parent
8210b8bee9
commit
1ef298aac6
|
@ -284,7 +284,7 @@ export async function initUserSession({ watcher, podName, proxyInfo }) {
|
|||
}
|
||||
}
|
||||
resolve({
|
||||
exec: (cmdline, { on, pty }) => {
|
||||
exec: async (cmdline, { on, pty }) => {
|
||||
// on :: { stdout, stderr, exit, error, close }
|
||||
if (pty) {
|
||||
cmdline = ["/riju-bin/ptyify", ...cmdline];
|
||||
|
@ -312,6 +312,10 @@ export async function initUserSession({ watcher, podName, proxyInfo }) {
|
|||
}
|
||||
);
|
||||
}
|
||||
await new Promise((resolve, reject) => {
|
||||
conn.on("open", resolve);
|
||||
conn.on("error", reject);
|
||||
});
|
||||
conn.on("message", (msg) => {
|
||||
let event, data, text, exitStatus;
|
||||
try {
|
||||
|
@ -352,7 +356,7 @@ export async function initUserSession({ watcher, podName, proxyInfo }) {
|
|||
return {
|
||||
stdin: {
|
||||
write: (data) =>
|
||||
conn.write(JSON.stringify({ event: "stdin", data })),
|
||||
conn.send(JSON.stringify({ event: "stdin", data })),
|
||||
},
|
||||
};
|
||||
},
|
||||
|
|
|
@ -57,8 +57,8 @@ async function main() {
|
|||
handlePtyInput: (data) => handlePtyInput(data),
|
||||
handlePtyExit: (_status) => {},
|
||||
});
|
||||
await new Promise((resolve) => {
|
||||
const exec = session.exec(["bash"], {
|
||||
await new Promise(async (resolve) => {
|
||||
const exec = await session.exec(["bash"], {
|
||||
pty: true,
|
||||
on: {
|
||||
stdout: (data) => pty.handlePtyOutput(data),
|
||||
|
|
|
@ -2,7 +2,6 @@ import { spawn } from "child_process";
|
|||
import { promises as fs } from "fs";
|
||||
import process from "process";
|
||||
|
||||
import TailFile from "@logdna/tail-file";
|
||||
import * as Sentry from "@sentry/node";
|
||||
import * as tmp from "tmp-promise";
|
||||
import { v4 as getUUIDOrig } from "uuid";
|
||||
|
@ -188,25 +187,40 @@ export function deptyify({ handlePtyInput, handlePtyExit }) {
|
|||
}
|
||||
});
|
||||
});
|
||||
const input = new TailFile(`${dir.path}/input`, {
|
||||
encoding: "utf-8",
|
||||
});
|
||||
input.on("data", (data) => handlePtyInput(data));
|
||||
input.on("tail_error", logError);
|
||||
input.on("error", logError);
|
||||
await input.start();
|
||||
const output = await fs.open(`${dir.path}/output`, "w");
|
||||
const proc = spawn(
|
||||
"system/out/riju-pty",
|
||||
`${process.cwd()}/system/out/riju-pty`,
|
||||
["-f", "sh", "-c", "cat > input & cat output"],
|
||||
{
|
||||
cwd: dir.path,
|
||||
stdio: "inherit",
|
||||
}
|
||||
);
|
||||
await new Promise((resolve, reject) => {
|
||||
proc.on("spawn", resolve);
|
||||
proc.on("error", reject);
|
||||
});
|
||||
proc.on("exit", (status) => {
|
||||
handlePtyExit(status);
|
||||
triggerDone();
|
||||
});
|
||||
const [input, output] = await new Promise((resolve, reject) => {
|
||||
setTimeout(() => reject("timed out"), 5000);
|
||||
resolve(
|
||||
Promise.all([
|
||||
fs.open(`${dir.path}/input`, "r"),
|
||||
fs.open(`${dir.path}/output`, "w"),
|
||||
])
|
||||
);
|
||||
});
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
while (true) {
|
||||
handlePtyInput(await input.read({ encoding: "utf-8" }));
|
||||
}
|
||||
} catch (err) {
|
||||
logError(err);
|
||||
}
|
||||
}, 0);
|
||||
resolve({
|
||||
handlePtyOutput: async (data) => {
|
||||
await output.write(data);
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
"@babel/preset-env": "^7.12.11",
|
||||
"@balena/dockerignore": "^1.0.2",
|
||||
"@kubernetes/client-node": "^0.18.0",
|
||||
"@logdna/tail-file": "^3.0.0",
|
||||
"@sentry/node": "^6.11.0",
|
||||
"async-lock": "^1.2.6",
|
||||
"babel-loader": "^8.2.2",
|
||||
|
|
|
@ -904,11 +904,6 @@
|
|||
optionalDependencies:
|
||||
openid-client "^5.3.0"
|
||||
|
||||
"@logdna/tail-file@^3.0.0":
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@logdna/tail-file/-/tail-file-3.0.0.tgz#0120353e59bf04b318d4861684e95682b0e85071"
|
||||
integrity sha512-aZy8XzJI9zwl7gbmQa1L5Hr6yJbS062OMQJ7I9sqHD/QMEBfwlhxyytJ4Qe2jAoimefuabopEi4Gk+t/7to6/A==
|
||||
|
||||
"@sentry/core@6.11.0":
|
||||
version "6.11.0"
|
||||
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.11.0.tgz#40e94043afcf6407a109be26655c77832c64e740"
|
||||
|
|
Loading…
Reference in New Issue