1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix compute unix shell environment timeout (#6516)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2022-11-04 13:20:19 +02:00 committed by GitHub
parent c527014011
commit d63bf277b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,10 +9,10 @@ import spawnInjectable from "../../child-process/spawn.injectable";
import randomUUIDInjectable from "../../crypto/random-uuid.injectable"; import randomUUIDInjectable from "../../crypto/random-uuid.injectable";
export interface UnixShellEnvOptions { export interface UnixShellEnvOptions {
signal?: AbortSignal; signal: AbortSignal;
} }
export type ComputeUnixShellEnvironment = (shell: string, opts?: UnixShellEnvOptions) => Promise<EnvironmentVariables>; export type ComputeUnixShellEnvironment = (shell: string, opts: UnixShellEnvOptions) => Promise<EnvironmentVariables>;
const computeUnixShellEnvironmentInjectable = getInjectable({ const computeUnixShellEnvironmentInjectable = getInjectable({
id: "compute-unix-shell-environment", id: "compute-unix-shell-environment",
@ -46,7 +46,7 @@ const computeUnixShellEnvironmentInjectable = getInjectable({
}; };
}; };
return async (shellPath, opts = {}) => { return async (shellPath, opts) => {
const runAsNode = process.env["ELECTRON_RUN_AS_NODE"]; const runAsNode = process.env["ELECTRON_RUN_AS_NODE"];
const noAttach = process.env["ELECTRON_NO_ATTACH_CONSOLE"]; const noAttach = process.env["ELECTRON_NO_ATTACH_CONSOLE"];
const env = { const env = {
@ -61,12 +61,11 @@ const computeUnixShellEnvironmentInjectable = getInjectable({
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const shellProcess = spawn(shellPath, shellArgs, { const shellProcess = spawn(shellPath, shellArgs, {
detached: true, detached: true,
signal: opts.signal,
env, env,
}); });
const stdout: Buffer[] = []; const stdout: Buffer[] = [];
opts.signal?.addEventListener("abort", () => shellProcess.kill());
shellProcess.stdout.on("data", b => stdout.push(b)); shellProcess.stdout.on("data", b => stdout.push(b));
shellProcess.on("error", (err) => reject(err)); shellProcess.on("error", (err) => reject(err));