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: Retry on timeout #106

Merged
merged 2 commits into from Dec 30, 2022
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
14 changes: 10 additions & 4 deletions dist/index.js
Expand Up @@ -1005,14 +1005,15 @@ function runRetryCmd(inputs) {
function runCmd(attempt, inputs) {
var _a, _b;
return __awaiter(this, void 0, void 0, function () {
var end_time, executable, child;
var end_time, executable, timeout, child;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
end_time = Date.now() + (0, inputs_1.getTimeout)(inputs);
executable = getExecutable(inputs);
exit = 0;
done = false;
timeout = false;
(0, core_1.debug)("Running command ".concat(inputs.command, " on ").concat(OS, " using shell ").concat(executable));
child = attempt > 1 && inputs.new_command_on_retry
? (0, child_process_1.spawn)(inputs.new_command_on_retry, { shell: executable })
Expand All @@ -1026,13 +1027,17 @@ function runCmd(attempt, inputs) {
child.on('exit', function (code, signal) {
(0, core_1.debug)("Code: ".concat(code));
(0, core_1.debug)("Signal: ".concat(signal));
if (code && code > 0) {
exit = code;
}
// timeouts are killed manually
if (signal === 'SIGTERM') {
return;
}
// On Windows signal is null.
if (timeout) {
return;
}
if (code && code > 0) {
exit = code;
}
done = true;
});
_c.label = 1;
Expand All @@ -1045,6 +1050,7 @@ function runCmd(attempt, inputs) {
_c.label = 4;
case 4:
if (!(!done && child.pid)) return [3 /*break*/, 6];
timeout = true;
(0, tree_kill_1.default)(child.pid);
return [4 /*yield*/, (0, util_1.retryWait)(milliseconds_1.default.seconds(inputs.retry_wait_seconds))];
case 5:
Expand Down
16 changes: 13 additions & 3 deletions src/index.ts
Expand Up @@ -71,6 +71,7 @@ async function runCmd(attempt: number, inputs: Inputs) {

exit = 0;
done = false;
let timeout = false;

debug(`Running command ${inputs.command} on ${OS} using shell ${executable}`);
const child =
Expand All @@ -88,13 +89,21 @@ async function runCmd(attempt: number, inputs: Inputs) {
child.on('exit', (code, signal) => {
debug(`Code: ${code}`);
debug(`Signal: ${signal}`);
if (code && code > 0) {
exit = code;
}

// timeouts are killed manually
if (signal === 'SIGTERM') {
return;
}

// On Windows signal is null.
if (timeout) {
return;
}

if (code && code > 0) {
exit = code;
}

done = true;
});

Expand All @@ -103,6 +112,7 @@ async function runCmd(attempt: number, inputs: Inputs) {
} while (Date.now() < end_time && !done);

if (!done && child.pid) {
timeout = true;
kill(child.pid);
await retryWait(ms.seconds(inputs.retry_wait_seconds));
throw new Error(`Timeout of ${getTimeout(inputs)}ms hit`);
Expand Down