Closed wizo06 closed 3 years ago
Merging #76 into master will decrease coverage by
0.06%
. The diff coverage is100.00%
.
@@ Coverage Diff @@
## master #76 +/- ##
==========================================
- Coverage 90.41% 90.34% -0.07%
==========================================
Files 2 2
Lines 146 145 -1
==========================================
- Hits 132 131 -1
Misses 14 14
Impacted Files | Coverage Δ | |
---|---|---|
lib/retry_operation.js | 86.31% <100.00%> (-0.15%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update b316bfc...a9a5515. Read the comment docs.
@tim-kos Hi, is this planned to be merged?
@tim-kos is there plans to publish a new version with this fix?
0.13.1 pushed with the patch!
TLDR (short explanation)
Problem 1
retry()
was not properly resetting.this._originalTimeouts
was being modified when callingthis._timeouts.shift()
.Solution 1
Before
After
Problem 2
When
forever: true
andretries
has been reached, it would keep retrying (expected behaviour becauseforever: true
) however it would start from the beginning ofthis._cachedTimeouts
again. The expected behaviour is to keep retrying with the last interval inthis._cachedTimeouts
.Solution 2
Before
After
Long explanation
Problem 1
The way
node-retry
works is by creating an array with a length ofretries
, whereretries
is the max number of retries. This array is stored in two variables,this._originalTimeouts
andthis._timeouts
. Each element in this array, is the interval (in milliseconds) in-between each retry/attempt.For each retry/attempt,
this._timeouts
is.shift()
'ed.When
retryOperation.reset()
is called,this._timeouts
is restored by referencingthis._originalTimeouts
.Arrays in Javascript are mutable, which means
this._timeouts = this._originalTimeouts;
does not make a new copy ofthis._originalTimeouts
intothis._timeouts
. Therefore, whenthis._timeouts
is.shift()
'ed,this._originalTimeouts
also gets.shift()
'ed, resulting in the loss of the intervals inthis._originalTimeouts
.Solution 1
Make a new copy of
this._originalTimeouts
and then assign it tothis._timeouts
.Before
After
Reference
Read more about
.shift()
here Read more about.slice()
here Read more about mutable hereProblem 2
The way
node-retry
works is by creating an array with a length ofretries
, whereretries
is the max number of retries. This array is stored inthis._timeouts
. Each element in this array, is the interval (in milliseconds) in-between each retry/attempt.If
forever: true
, a copy ofthis._timeouts
is made and assigned tothis._cachedTimeouts
.When
forever: true
andretries
has been reached, it would keep retrying (expected behaviour becauseforever: true
) however it would start from the beginning ofthis._cachedTimeouts
again. The expected behaviour is to keep retrying with the last interval inthis._cachedTimeouts
.An example of a current behaviour: suppose an array with the following intervals:
Retries would behave like so:
An example of an expected behaviour: suppose the same array with the same intervals:
Retries should behave like so:
Solution 2
Assign the last interval of
this._cachedTimeouts
totimeout
.timeout
is used asdelay
argument forsetTImeout
.Before
After