Skip to content

Commit

Permalink
feat(config): add safeguard timeouts (#12604)
Browse files Browse the repository at this point in the history
* Add safeguard timeouts #2804

* Fix unit tests

* Fix unit tests

* Update lib/util/exec/index.ts

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>

* Changes after code review

* Fixes after merge

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
3 people committed Nov 25, 2021
1 parent 6ad29b6 commit 6293641
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/usage/self-hosted-configuration.md
Expand Up @@ -250,6 +250,11 @@ e.g.

## endpoint

## executionTimeout

Default execution timeout in minutes for child processes Renovate creates.
If this option is not set, Renovate will fallback to 15 minutes.

## exposeAllEnv

By default, Renovate only passes a limited set of environment variables to package managers.
Expand Down
1 change: 1 addition & 0 deletions lib/config/global.ts
Expand Up @@ -16,6 +16,7 @@ export class GlobalConfig {
'dockerUser',
'dryRun',
'exposeAllEnv',
'executionTimeout',
'localDir',
'migratePresets',
'privateKey',
Expand Down
8 changes: 8 additions & 0 deletions lib/config/options/index.ts
Expand Up @@ -747,6 +747,14 @@ const options: RenovateOptions[] = [
subType: 'string',
default: [],
},
{
name: 'executionTimeout',
description:
'Default execution timeout in minutes for child processes Renovate creates.',
type: 'integer',
default: 15,
globalOnly: true,
},
{
name: 'aliases',
description: 'Aliases for registries, package manager specific.',
Expand Down
1 change: 1 addition & 0 deletions lib/config/types.ts
Expand Up @@ -102,6 +102,7 @@ export interface RepoGlobalConfig {
dockerImagePrefix?: string;
dockerUser?: string;
dryRun?: boolean;
executionTimeout?: number;
exposeAllEnv?: boolean;
migratePresets?: Record<string, string>;
privateKey?: string;
Expand Down
20 changes: 20 additions & 0 deletions lib/util/exec/index.spec.ts
Expand Up @@ -542,6 +542,26 @@ describe('util/exec/index', () => {
},
],

[
'Default timeout from executionTimeout config option',
{
processEnv,
inCmd,
inOpts: {},
outCmd,
outOpts: [
{
cwd,
encoding,
env: envMock.basic,
timeout: 30 * 60 * 1000,
maxBuffer: 10485760,
},
],
adminConfig: { executionTimeout: 30 },
},
],

[
'Explicit maxBuffer',
{
Expand Down
12 changes: 10 additions & 2 deletions lib/util/exec/index.ts
Expand Up @@ -68,6 +68,7 @@ function getCwd({ cwd, cwdFile }: ExecOptions): string {
}

function getRawExecOptions(opts: ExecOptions): RawExecOptions {
const defaultExecutionTimeout = GlobalConfig.get('executionTimeout');
const execOptions: ExecOptions = { ...opts };
delete execOptions.extraEnv;
delete execOptions.docker;
Expand All @@ -82,8 +83,15 @@ function getRawExecOptions(opts: ExecOptions): RawExecOptions {
env: childEnv,
cwd,
};
// Set default timeout to 15 minutes
rawExecOptions.timeout = rawExecOptions.timeout || 15 * 60 * 1000;
// Set default timeout config.executionTimeout if specified; othrwise to 15 minutes
if (!rawExecOptions.timeout) {
if (defaultExecutionTimeout) {
rawExecOptions.timeout = defaultExecutionTimeout * 60 * 1000;
} else {
rawExecOptions.timeout = 15 * 60 * 1000;
}
}

// Set default max buffer size to 10MB
rawExecOptions.maxBuffer = rawExecOptions.maxBuffer || 10 * 1024 * 1024;
return rawExecOptions;
Expand Down

0 comments on commit 6293641

Please sign in to comment.