Skip to content

Commit

Permalink
Avoid infinite loop and patch exponential backoff edge case (#68)
Browse files Browse the repository at this point in the history
* Don't break exponential backoff when minTimeout is zero

* Hope this is how versioning works on this project!

* No more infinite loops when innocently setting retries to Infinity
  • Loading branch information
gittyeric committed Dec 16, 2020
1 parent b316bfc commit bf0ae23
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var RetryOperation = require('./retry_operation');
exports.operation = function(options) {
var timeouts = exports.timeouts(options);
return new RetryOperation(timeouts, {
forever: options && options.forever,
forever: options && (options.forever || options.retries === Infinity),
unref: options && options.unref,
maxRetryTime: options && options.maxRetryTime
});
Expand Down Expand Up @@ -51,7 +51,7 @@ exports.createTimeout = function(attempt, opts) {
? (Math.random() + 1)
: 1;

var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
timeout = Math.min(timeout, opts.maxTimeout);

return timeout;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "retry",
"description": "Abstraction for exponential and custom retry strategies for failed operations.",
"license": "MIT",
"version": "0.12.0",
"version": "0.13.0",
"homepage": "https://github.com/tim-kos/node-retry",
"repository": {
"type": "git",
Expand Down

0 comments on commit bf0ae23

Please sign in to comment.