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

Retries do not support backoff #20

Closed
TimFerrell opened this issue Jul 27, 2018 · 2 comments
Closed

Retries do not support backoff #20

TimFerrell opened this issue Jul 27, 2018 · 2 comments

Comments

@TimFerrell
Copy link

When calling a service with the retry option, it will immediately make a retry request after the first failure:

if (_.has(options, 'retry')) {
const retryOpts = options.retry
const callOpts = options ? _.omit(options, 'retry') : options
if (_.isFunction(fn)) {
async.retry(retryOpts, rCb => {
v.call(this.client, arg, metadata, callOpts, rCb)
}, fn)
} else {
return new Promise((resolve, reject) => {
async.retry(retryOpts, rCb => {
v.call(this.client, arg, metadata, callOpts, rCb)
}, (err, res) => {
if (err) reject(err)
else resolve(res)
})
})
}

General guidance is to implement backoffs when retrying to prevent overloading the server.

The suggestion is to support a function that returns the amount of time to delay before attempting the retry. This approach would support different approaches to backoffs (constant value, linear, exponential, jitter, no jitter).

Something similar to this:

/**
 * @param {number} requestAttempts Amount of times that the request has been made.
 */
function backoff(requestAttempts) {
  return (requestAttempts * 20);
}
@bojand
Copy link
Owner

bojand commented Jul 27, 2018

The retry option is just async.retry(). So you could do:

const res = await client.sayHello({ name: 'Bob' }, {}, { retry: { times: 3, interval: 200 } })
console.log(res)

and that will do retries with 200 milliseconds between retry intervals.

You can also indeed use a function as well:

const res = await client.sayHello({
  name: 'Bob'
}, {}, {
  retry: {
    times: 10,
    interval: function(retryCount) {
      return 50 * Math.pow(2, retryCount);
    }
  }
}) 

console.log(res)

Is this not working for you?

@TimFerrell
Copy link
Author

That works! Thanks for the reply, and my apologies for not catching this myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants