mirror of
https://github.com/nick-fields/retry.git
synced 2026-02-11 23:55:28 +00:00
fix: Retry on timeout (#106)
* fix: do not set return value for timed out runs Commands that are killed manually due to timeout rarely returns a success status code (0). These codes should not be treated as errors but simply produced because of the timeout. * fix(windows): use variable to track timeout Use a variable to track timeout instead of relying on SIGTERM, as processes on Windows are not killed using signals.
This commit is contained in:
16
src/index.ts
16
src/index.ts
@@ -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 =
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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`);
|
||||
|
||||
Reference in New Issue
Block a user