-
Notifications
You must be signed in to change notification settings - Fork 89
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
'operation.attempt' callback gets executed more than once with same 'attempt' number #45
Comments
Not sure why this happens, however I've opted to use the following approach until we can figure this issue out: const maxAttempts = 3;
let attempt = 1;
while (attempt <= maxAttempts) {
try {
console.log(`doing ${attempt}: ${command}`);
const execResult = await execPromise(command);
// Do something with execResult
cosole.log(execResult)
break;
} catch (e) {
this.log.error(e);
// Sleep using linear backoff strategy (5s after first attempt, 10s after second attempt)
if (attempt < maxAttempt) {
await new Promise(resolve => setTimeout(resolve, 5000 * attempt));
}
attempt += 1;
}
} |
So you are getting the same issue as me? Do you also get it with node-promise-retry? |
@rightaway Yep same issue. I don't use |
Hey ladies and gentlemen, I will look into this soon. I am just really busy with Transloadit right now. Sorry for the delay. :/ |
FWIW, the following test program seems to work fine for me. const retry = require("retry");
const sleep = timeout =>
new Promise(resolve => setTimeout(resolve, timeout));
function log(msg) {
console.log(`${new Date().toLocaleString()}: ${msg}`);
}
async function asyncThrow() {
await sleep(1000);
throw 'whoops';
}
const operation = retry.operation({
retries: 3,
factor: 2,
maxTimeout: 10000,
randomize: true
});
operation.attempt(async (attemptNumber) => {
try {
log(`attemptNumber = ${attemptNumber} - calling asyncThrow`);
await asyncThrow();
}
catch(err) {
if (operation.retry(err)) {
log('retrying.');
} else {
log('giving up.');
}
}
}); Here's the output I get:
|
Hm okay, thanks for doing this. @rightaway Do you mind posting your complete code here? |
Closing this then for now, because the error is unlikely in node-retry, but rather in the userland code. @avranju 's example works as expected. |
I've tried to make
node-retry
work with Promises, so that I can call it for example likeawait retryCommand('curl http://example.com')
. But it's not working as expected, because I get numerousconsole.log
output with the sameattempt
number before theattempt
number gets incremented. For example:Why would the
operation.attempt
callback get executed again with the sameattempt
number? I'm passing anasync
callback tooperation.attempt
but I don't see why that would be the problem.Basically the code checks if the error should be retried (with a custom
errorIsRetriable(e)
function), and if not then the Promise rejects right away.The text was updated successfully, but these errors were encountered: