Git Product home page Git Product logo

Comments (7)

tim-kos avatar tim-kos commented on August 10, 2024 2

Hey ladies and gentlemen,

I will look into this soon. I am just really busy with Transloadit right now.

Sorry for the delay. :/

from node-retry.

matomesc avatar matomesc commented on August 10, 2024

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;
  }
}

from node-retry.

rightaway avatar rightaway commented on August 10, 2024

So you are getting the same issue as me? Do you also get it with node-promise-retry?
See my issue in IndigoUnited/node-promise-retry#14, I'm getting it there too.

from node-retry.

matomesc avatar matomesc commented on August 10, 2024

@rightaway Yep same issue. I don't use node-promise-retry but it's just a wrapper around node-retry so it makes sense that you encountered this issue there as well.

from node-retry.

avranju avatar avranju commented on August 10, 2024

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:

2017-11-20 14:34:00: attemptNumber = 1 - calling asyncThrow
2017-11-20 14:34:01: retrying.
2017-11-20 14:34:02: attemptNumber = 2 - calling asyncThrow
2017-11-20 14:34:03: retrying.
2017-11-20 14:34:07: attemptNumber = 3 - calling asyncThrow
2017-11-20 14:34:08: retrying.
2017-11-20 14:34:13: attemptNumber = 4 - calling asyncThrow
2017-11-20 14:34:14: giving up.

from node-retry.

tim-kos avatar tim-kos commented on August 10, 2024

Hm okay, thanks for doing this.

@rightaway Do you mind posting your complete code here?

from node-retry.

tim-kos avatar tim-kos commented on August 10, 2024

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.

from node-retry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.