Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: abort branch if child process receives SIGTERM #8992

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/constants/error-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const REPOSITORY_UNINITIATED = 'uninitiated';
export const REPOSITORY_CHANGED = 'repository-changed';
export const TEMPORARY_ERROR = 'temporary-error';
export const NO_VULNERABILITY_ALERTS = 'no-vulnerability-alerts';
export const INTERRUPTED = 'interrupted';

// Manager Error
export const MANAGER_LOCKFILE_ERROR = 'lockfile-error';
Expand Down
8 changes: 7 additions & 1 deletion lib/manager/bundler/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { quote } from 'shlex';
import { BUNDLER_INVALID_CREDENTIALS } from '../../constants/error-messages';
import {
BUNDLER_INVALID_CREDENTIALS,
INTERRUPTED,
} from '../../constants/error-messages';
import { logger } from '../../logger';
import { HostRule } from '../../types';
import * as memCache from '../../util/cache/memory';
Expand Down Expand Up @@ -158,6 +161,9 @@ export async function updateArtifacts(
},
];
} catch (err) /* istanbul ignore next */ {
if (err.message === INTERRUPTED) {
throw err;
}
const output = `${String(err.stdout)}\n${String(err.stderr)}`;
if (
err.message.includes('fatal: Could not parse object') ||
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/cargo/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { quote } from 'shlex';
import { INTERRUPTED } from '../../constants/error-messages';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
import {
Expand Down Expand Up @@ -105,6 +106,10 @@ export async function updateArtifacts({
},
];
} catch (err) {
// istanbul ignore if
if (err.message === INTERRUPTED) {
throw err;
}
logger.warn({ err }, 'Failed to update Cargo lock file');
return [
{
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/cocoapods/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { quote } from 'shlex';
import { dirname, join } from 'upath';
import { INTERRUPTED } from '../../constants/error-messages';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
import {
Expand Down Expand Up @@ -82,6 +83,10 @@ export async function updateArtifacts({
try {
await exec(cmd, execOptions);
} catch (err) {
// istanbul ignore if
if (err.message === INTERRUPTED) {
throw err;
}
return [
{
artifactError: {
Expand Down
9 changes: 8 additions & 1 deletion lib/manager/composer/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import is from '@sindresorhus/is';
import { quote } from 'shlex';
import upath from 'upath';
import { getAdminConfig } from '../../config/admin';
import { SYSTEM_INSUFFICIENT_DISK_SPACE } from '../../constants/error-messages';
import {
INTERRUPTED,
SYSTEM_INSUFFICIENT_DISK_SPACE,
} from '../../constants/error-messages';
import {
PLATFORM_TYPE_GITHUB,
PLATFORM_TYPE_GITLAB,
Expand Down Expand Up @@ -193,6 +196,10 @@ export async function updateArtifacts({

return res;
} catch (err) {
// istanbul ignore if
if (err.message === INTERRUPTED) {
throw err;
}
if (
err.message?.includes(
'Your requirements could not be resolved to an installable set of packages.'
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/gomod/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { quote } from 'shlex';
import { dirname, join } from 'upath';
import { INTERRUPTED } from '../../constants/error-messages';
import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
Expand Down Expand Up @@ -154,6 +155,10 @@ export async function updateArtifacts({
}
return res;
} catch (err) {
// istanbul ignore if
if (err.message === INTERRUPTED) {
throw err;
}
logger.debug({ err }, 'Failed to update go.sum');
return [
{
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/gradle-wrapper/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { stat } from 'fs-extra';
import { resolve } from 'upath';
import { INTERRUPTED } from '../../constants/error-messages';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
import { readLocalFile, writeLocalFile } from '../../util/fs';
Expand Down Expand Up @@ -92,6 +93,10 @@ export async function updateArtifacts({
try {
await exec(cmd, execOptions);
} catch (err) {
// istanbul ignore if
if (err.message === INTERRUPTED) {
throw err;
}
logger.warn(
{ err },
'Error executing gradle wrapper update command. It can be not a critical one though.'
Expand Down
4 changes: 4 additions & 0 deletions lib/manager/gradle/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Stats } from 'fs';
import { stat } from 'fs-extra';
import upath from 'upath';
import { INTERRUPTED } from '../../constants/error-messages';
import { LANGUAGE_JAVA } from '../../constants/languages';
import * as datasourceMaven from '../../datasource/maven';
import { logger } from '../../logger';
Expand Down Expand Up @@ -72,6 +73,9 @@ export async function executeGradle(
logger.debug({ cmd }, 'Start gradle command');
({ stdout, stderr } = await exec(cmd, execOptions));
} catch (err) /* istanbul ignore next */ {
if (err.message === INTERRUPTED) {
throw err;
}
if (err.code === TIMEOUT_CODE) {
throw new ExternalHostError(err, 'gradle');
}
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/helmv3/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { quote } from 'shlex';
import { INTERRUPTED } from '../../constants/error-messages';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
import {
Expand Down Expand Up @@ -63,6 +64,10 @@ export async function updateArtifacts({
},
];
} catch (err) {
// istanbul ignore if
if (err.message === INTERRUPTED) {
throw err;
}
logger.warn({ err }, 'Failed to update Helm lock file');
return [
{
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/mix/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { quote } from 'shlex';
import { INTERRUPTED } from '../../constants/error-messages';
import { logger } from '../../logger';
import { exec } from '../../util/exec';
import { BinarySource } from '../../util/exec/common';
Expand Down Expand Up @@ -62,6 +63,10 @@ export async function updateArtifacts({
const command = [...cmdParts, ...updatedDeps.map(quote)].join(' ');
await exec(command, { cwd });
} catch (err) {
// istanbul ignore if
if (err.message === INTERRUPTED) {
throw err;
}
logger.warn(
{ err, message: err.message },
'Failed to update Mix lock file'
Expand Down
4 changes: 4 additions & 0 deletions lib/manager/npm/post-update/lerna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import semver, { validRange } from 'semver';
import { quote } from 'shlex';
import { join } from 'upath';
import { getAdminConfig } from '../../../config/admin';
import { INTERRUPTED } from '../../../constants/error-messages';
import { logger } from '../../../logger';
import { ExecOptions, exec } from '../../../util/exec';
import type { PackageFile, PostUpdateConfig } from '../../types';
Expand Down Expand Up @@ -113,6 +114,9 @@ export async function generateLockFiles(
cmd.push(lernaCommand);
await exec(cmd, execOptions);
} catch (err) /* istanbul ignore next */ {
if (err.message === INTERRUPTED) {
throw err;
}
logger.debug(
{
cmd,
Expand Down
8 changes: 7 additions & 1 deletion lib/manager/npm/post-update/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { validRange } from 'semver';
import { quote } from 'shlex';
import { join } from 'upath';
import { getAdminConfig } from '../../../config/admin';
import { SYSTEM_INSUFFICIENT_DISK_SPACE } from '../../../constants/error-messages';
import {
INTERRUPTED,
SYSTEM_INSUFFICIENT_DISK_SPACE,
} from '../../../constants/error-messages';
import { logger } from '../../../logger';
import { ExecOptions, exec } from '../../../util/exec';
import { move, pathExists, readFile, remove } from '../../../util/fs';
Expand Down Expand Up @@ -135,6 +138,9 @@ export async function generateLockFile(
// Read the result
lockFile = await readFile(join(cwd, filename), 'utf8');
} catch (err) /* istanbul ignore next */ {
if (err.message === INTERRUPTED) {
throw err;
}
logger.debug(
{
err,
Expand Down
4 changes: 4 additions & 0 deletions lib/manager/npm/post-update/pnpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { validRange } from 'semver';
import { quote } from 'shlex';
import { join } from 'upath';
import { getAdminConfig } from '../../../config/admin';
import { INTERRUPTED } from '../../../constants/error-messages';
import { logger } from '../../../logger';
import { ExecOptions, exec } from '../../../util/exec';
import { readFile, remove } from '../../../util/fs';
Expand Down Expand Up @@ -85,6 +86,9 @@ export async function generateLockFile(
await exec(`${cmd} ${args}`, execOptions);
lockFile = await readFile(lockFileName, 'utf8');
} catch (err) /* istanbul ignore next */ {
if (err.message === INTERRUPTED) {
throw err;
}
logger.debug(
{
cmd,
Expand Down
8 changes: 7 additions & 1 deletion lib/manager/npm/post-update/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { gte, minVersion, validRange } from 'semver';
import { quote } from 'shlex';
import { join } from 'upath';
import { getAdminConfig } from '../../../config/admin';
import { SYSTEM_INSUFFICIENT_DISK_SPACE } from '../../../constants/error-messages';
import {
INTERRUPTED,
SYSTEM_INSUFFICIENT_DISK_SPACE,
} from '../../../constants/error-messages';
import { id as npmId } from '../../../datasource/npm';
import { logger } from '../../../logger';
import { ExternalHostError } from '../../../types/errors/external-host-error';
Expand Down Expand Up @@ -182,6 +185,9 @@ export async function generateLockFile(
// Read the result
lockFile = await readFile(lockFileName, 'utf8');
} catch (err) /* istanbul ignore next */ {
if (err.message === INTERRUPTED) {
throw err;
}
logger.debug(
{
err,
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/nuget/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join } from 'path';
import { INTERRUPTED } from '../../constants/error-messages';
import { id } from '../../datasource/nuget';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
Expand Down Expand Up @@ -137,6 +138,10 @@ export async function updateArtifacts({
},
];
} catch (err) {
// istanbul ignore if
if (err.message === INTERRUPTED) {
throw err;
}
logger.debug({ err }, 'Failed to generate lock file');
return [
{
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/pip_requirements/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import is from '@sindresorhus/is';
import { INTERRUPTED } from '../../constants/error-messages';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
import { readLocalFile } from '../../util/fs';
Expand Down Expand Up @@ -52,6 +53,10 @@ export async function updateArtifacts({
},
];
} catch (err) {
// istanbul ignore if
if (err.message === INTERRUPTED) {
throw err;
}
logger.debug({ err }, `Failed to update ${packageFileName} file`);
return [
{
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/pipenv/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { quote } from 'shlex';
import { INTERRUPTED } from '../../constants/error-messages';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
import {
Expand Down Expand Up @@ -127,6 +128,10 @@ export async function updateArtifacts({
},
];
} catch (err) {
// istanbul ignore if
if (err.message === INTERRUPTED) {
throw err;
}
logger.debug({ err }, 'Failed to update Pipfile.lock');
return [
{
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/poetry/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { parse } from '@iarna/toml';
import is from '@sindresorhus/is';
import { quote } from 'shlex';
import { INTERRUPTED } from '../../constants/error-messages';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
import {
Expand Down Expand Up @@ -153,6 +154,10 @@ export async function updateArtifacts({
},
];
} catch (err) {
// istanbul ignore if
if (err.message === INTERRUPTED) {
throw err;
}
logger.debug({ err }, `Failed to update ${lockFileName} file`);
return [
{
Expand Down
18 changes: 18 additions & 0 deletions lib/util/exec/exec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { envMock } from '../../../test/exec-util';
import { setAdminConfig } from '../../config/admin';
import type { RepoAdminConfig } from '../../config/types';
import { INTERRUPTED } from '../../constants/error-messages';
import {
BinarySource,
ExecConfig,
Expand Down Expand Up @@ -775,4 +776,21 @@ describe(`Child process execution wrapper`, () => {
);
expect(removeDockerContainerSpy).toHaveBeenCalledTimes(2);
});
it('converts to INTERRUPTED', async () => {
cpExec.mockImplementation(() => {
class ErrorSignal extends Error {
signal?: string;
}
const error = new ErrorSignal();
error.signal = 'SIGTERM';
throw error;
});
const removeDockerContainerSpy = jest.spyOn(
dockerModule,
'removeDockerContainer'
);
const promise = exec('foobar', {});
await expect(promise).rejects.toThrow(INTERRUPTED);
expect(removeDockerContainerSpy).toHaveBeenCalledTimes(0);
});
});
5 changes: 5 additions & 0 deletions lib/util/exec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ExecOptions as ChildProcessExecOptions } from 'child_process';
import { dirname, join } from 'upath';
import { getAdminConfig } from '../../config/admin';
import type { RenovateConfig } from '../../config/types';
import { INTERRUPTED } from '../../constants/error-messages';
import { logger } from '../../logger';
import {
BinarySource,
Expand Down Expand Up @@ -157,6 +158,10 @@ export async function exec(
);
});
}
if (err.signal === `SIGTERM`) {
logger.debug({ err }, 'exec interrupted by SIGTERM');
throw new Error(INTERRUPTED);
}
throw err;
}
const durationMs = Math.round(Date.now() - startTime);
Expand Down