Skip to content

Commit cc9dd76

Browse files
Kartik Rajwesm
authored andcommitted
Set a timeout on running poetry CLI commands (microsoft/vscode-python#18212)
1 parent 802048a commit cc9dd76

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

extensions/positron-python/src/client/pythonEnvironments/base/info/environmentInfoService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createRunningWorkerPool, IWorkerPool, QueuePosition } from '../../../co
77
import { getInterpreterInfo, InterpreterInformation } from './interpreter';
88
import { buildPythonExecInfo } from '../../exec';
99
import { traceError, traceInfo } from '../../../logging';
10-
import { Conda, CONDA_RUN_TIMEOUT, isCondaEnvironment } from '../../common/environmentManagers/conda';
10+
import { Conda, CONDA_ACTIVATION_TIMEOUT, isCondaEnvironment } from '../../common/environmentManagers/conda';
1111
import { PythonEnvInfo, PythonEnvKind } from '.';
1212
import { normCasePath } from '../../common/externalDependencies';
1313

@@ -41,7 +41,7 @@ async function buildEnvironmentInfoUsingCondaRun(env: PythonEnvInfo): Promise<In
4141
}
4242
const interpreterInfo = await getInterpreterInfo(
4343
buildPythonExecInfo(python, undefined, env.executable.filename),
44-
CONDA_RUN_TIMEOUT,
44+
CONDA_ACTIVATION_TIMEOUT,
4545
);
4646
return interpreterInfo;
4747
}

extensions/positron-python/src/client/pythonEnvironments/common/environmentManagers/conda.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ export async function getPythonVersionFromConda(interpreterPath: string): Promis
202202

203203
// Minimum version number of conda required to be able to use 'conda run' with '--no-capture-output' flag.
204204
export const CONDA_RUN_VERSION = '4.9.0';
205-
export const CONDA_RUN_TIMEOUT = 45000;
205+
export const CONDA_ACTIVATION_TIMEOUT = 45000;
206+
const CONDA_GENERAL_TIMEOUT = 50000;
206207

207208
export const CONDA_RUN_SCRIPT = path.join(_SCRIPTS_DIR, 'conda_run_script.py');
208209

@@ -361,7 +362,7 @@ export class Conda {
361362
@cache(30_000, true, 10_000)
362363
// eslint-disable-next-line class-methods-use-this
363364
private async getInfoCached(command: string): Promise<CondaInfo> {
364-
const result = await exec(command, ['info', '--json'], { timeout: 50000 });
365+
const result = await exec(command, ['info', '--json'], { timeout: CONDA_GENERAL_TIMEOUT });
365366
traceVerbose(`conda info --json: ${result.stdout}`);
366367
return JSON.parse(result.stdout);
367368
}
@@ -430,7 +431,7 @@ export class Conda {
430431
if (info && info.conda_version) {
431432
versionString = info.conda_version;
432433
} else {
433-
const stdOut = await exec(this.command, ['--version'], { timeout: 50000 })
434+
const stdOut = await exec(this.command, ['--version'], { timeout: CONDA_GENERAL_TIMEOUT })
434435
.then((result) => result.stdout.trim())
435436
.catch<string | undefined>(() => undefined);
436437

extensions/positron-python/src/client/pythonEnvironments/common/environmentManagers/poetry.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export async function isPoetryEnvironment(interpreterPath: string): Promise<bool
8484
return false;
8585
}
8686

87+
const POETRY_TIMEOUT = 50000;
88+
8789
/** Wraps the "poetry" utility, and exposes its functionality.
8890
*/
8991
export class Poetry {
@@ -262,11 +264,12 @@ export class Poetry {
262264

263265
private async safeShellExecute(command: string, logVerbose = false) {
264266
// It has been observed that commands related to conda or poetry binary take upto 10-15 seconds unlike
265-
// python binaries. So for now no timeouts on them.
267+
// python binaries. So have a large timeout.
266268
const stopWatch = new StopWatch();
267269
const result = await shellExecute(command, {
268270
cwd: this.cwd,
269271
throwOnStdErr: true,
272+
timeout: POETRY_TIMEOUT,
270273
}).catch((ex) => {
271274
if (logVerbose) {
272275
traceVerbose(ex);

0 commit comments

Comments
 (0)