mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix timeout
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
76ca14663c
commit
47df54d828
@ -55,7 +55,8 @@ const setupShellInjectable = getInjectable({
|
||||
...process.env,
|
||||
};
|
||||
|
||||
logger.debug(`[SHELL-SYNC]: Synced shell env, and updating`, env, process.env);
|
||||
logger.info(`[SHELL-SYNC]: Synced shell env`);
|
||||
logger.debug(`[SHELL-SYNC]: updated env`, process.env);
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import isWindowsInjectable from "../../../common/vars/is-windows.injectable";
|
||||
import { disposer, hasTypedProperty, isString } from "../../../common/utils";
|
||||
import computeUnixShellEnvironmentInjectable from "./compute-unix-shell-environment.injectable";
|
||||
|
||||
export type EnvironmentVariables = Partial<Record<string, string>>;
|
||||
@ -28,39 +27,24 @@ const computeShellEnvironmentInjectable = getInjectable({
|
||||
return async (shell) => {
|
||||
const controller = new AbortController();
|
||||
const shellEnv = computeUnixShellEnvironment(shell, { signal: controller.signal });
|
||||
const cleanup = disposer();
|
||||
|
||||
const timeoutHandle = setTimeout(() => controller.abort(), 30_000);
|
||||
|
||||
cleanup.push(() => clearTimeout(timeoutHandle));
|
||||
const result = await shellEnv;
|
||||
|
||||
try {
|
||||
return {
|
||||
callWasSuccessful: true,
|
||||
response: await shellEnv,
|
||||
};
|
||||
} catch (error) {
|
||||
if (controller.signal.aborted) {
|
||||
return {
|
||||
callWasSuccessful: false,
|
||||
error: "Resolving shell environment is taking very long. Please review your shell configuration.",
|
||||
};
|
||||
}
|
||||
clearTimeout(timeoutHandle);
|
||||
|
||||
if (error && hasTypedProperty(error, "stderr", isString)) {
|
||||
return {
|
||||
callWasSuccessful: false,
|
||||
error: `${error}:\n${error.stderr}`,
|
||||
};
|
||||
}
|
||||
if (result.callWasSuccessful) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (controller.signal.aborted) {
|
||||
return {
|
||||
callWasSuccessful: false,
|
||||
error: String(error),
|
||||
error: `Resolving shell environment is taking very long. Please review your shell configuration: ${result.error}`,
|
||||
};
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@ -11,12 +11,13 @@ import loggerInjectable from "../../../common/logger.injectable";
|
||||
import processExecPathInjectable from "./execPath.injectable";
|
||||
import processEnvInjectable from "./env.injectable";
|
||||
import { object } from "../../../common/utils";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
|
||||
export interface UnixShellEnvOptions {
|
||||
signal: AbortSignal;
|
||||
}
|
||||
|
||||
export type ComputeUnixShellEnvironment = (shell: string, opts: UnixShellEnvOptions) => Promise<EnvironmentVariables>;
|
||||
export type ComputeUnixShellEnvironment = (shell: string, opts: UnixShellEnvOptions) => Promise<AsyncResult<EnvironmentVariables, string>>;
|
||||
|
||||
const getResetProcessEnv = (src: Partial<Record<string, string>>, overrides: Partial<Record<string, string>>): {
|
||||
resetEnvPairs: (target: Partial<Record<string, string>>) => void;
|
||||
@ -111,9 +112,17 @@ const computeUnixShellEnvironmentInjectable = getInjectable({
|
||||
shellProcess.on("error", (err) => reject(err));
|
||||
shellProcess.on("close", (code, signal) => {
|
||||
if (code || signal) {
|
||||
return reject(Object.assign(new Error(`Unexpected return code from spawned shell (code: ${code}, signal: ${signal})`), {
|
||||
const context = {
|
||||
code,
|
||||
signal,
|
||||
stdout: Buffer.concat(stdout).toString("utf-8"),
|
||||
stderr: Buffer.concat(stderr).toString("utf-8"),
|
||||
}));
|
||||
};
|
||||
|
||||
return resolve({
|
||||
callWasSuccessful: false,
|
||||
error: `Shell did not exit sucessfully: ${JSON.stringify(context, null, 4)}`,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
@ -123,12 +132,18 @@ const computeUnixShellEnvironmentInjectable = getInjectable({
|
||||
|
||||
const match = regex.exec(rawOutput);
|
||||
const strippedRawOutput = match ? match[1] : "{}";
|
||||
const resolvedEnv = JSON.parse(strippedRawOutput);
|
||||
const resolvedEnv = JSON.parse(strippedRawOutput) as Partial<Record<string, string>>;
|
||||
|
||||
resetEnvPairs(resolvedEnv);
|
||||
resolve(resolvedEnv);
|
||||
resolve({
|
||||
callWasSuccessful: true,
|
||||
response: resolvedEnv,
|
||||
});
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
resolve({
|
||||
callWasSuccessful: false,
|
||||
error: String(err),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user