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

fix: non-zero delay between first attempt and first retry for linear and exp strategy #163

Conversation

jgehrcke
Copy link
Contributor

One of the issues discussed in #122 is that for the linear and exponential strategy the delay between the first and second HTTP request is 0.

This PR:

  • makes this first delay non-zero by moving (err.config as RaxConfig).raxConfig!.currentRetryAttempt! += 1; to before doing the math that uses the result.
  • introduces the variable retrycount and adds a comment explaining what it really means to make future work on this code section a little more straight-forward.
  • adds one new test for each of the strategies, explicitly measuring the delay time between first and second HTTP request

Note that for measuring time difference I wanted to use a monotonic time source and the "modern" process.hrtime.bigint() and therefore I was bumping the engine in package.json.

The duration of npm run test changed from ~7 s to ~27 s because of the delay now hitting in.

@JustinBeckwith I would appreciate review!

Note that next up we can maybe change the time constants for the exponential backoff as was also proposed in #122; to make the first delay a little smaller than 0.5 seconds.

See issue JustinBeckwith#122.

This is to confirm that the delay
between the first (actual) attempt
and the first retry is not zero,
but the configured delay.

tests: prettier format (noop)

tests: prettier format (noop)
The mutation did not affect the code below.
This is for issue JustinBeckwith#122.

calc delay: prettier (format)
@jgehrcke jgehrcke changed the title Fix delay between first attempt and first retry for linear and exp strategy fix: non-zero delay between first attempt and first retry for linear and exp strategy Aug 16, 2021
@jgehrcke
Copy link
Contributor Author

jgehrcke commented Aug 16, 2021

Note that for measuring time difference I wanted to use a monotonic time source and the "modern" process.hrtime.bigint() and therefore I was bumping the engine in package.json.

Hm. Should not even be needed. https://nodejs.org/docs/latest-v10.x/api/process.html#process_process_hrtime_bigint added in: v10.7.0. Dropping that commit.

Found that state is not retained across
retries when mutating
`config.currentRetryAttempt` here.
@jgehrcke jgehrcke force-pushed the jp/delay-between-first-attempt-and-first-retry branch from 9efeff2 to c059361 Compare August 16, 2021 11:35
Copy link
Owner

@JustinBeckwith JustinBeckwith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. Thank you!

@JustinBeckwith
Copy link
Owner

Only problem - looks like you need to run an npm run fix to address the lint issue. After that, happy to land this!

This is to address the `gts fix` error

    The 'process.hrtime.bigint' is not supported
    until Node.js 10.7.0. The configured version
    range is '>=10.0.0'

This function is only used in the test suite
so maybe it's not the best solution to change
the NodeJS version requirement for the
entire package. However, whoever runs this on
NodeJS older than 10.7.0 (released on
2018-07-18) might want to be encouraged to
use a more recent version.
@jgehrcke
Copy link
Contributor Author

looks like you need to run an npm run fix to address the lint issue. After that, happy to land this!

Thank you. Addressed the "lint issue" pragmatically now. See commit message. Let me know if you disagree, can probably be solved differently w/o touching the engine field. Thanks for the feedback, Justin!

@JustinBeckwith
Copy link
Owner

Heh, curiosity killed the cat - what code did you write that ran afoul of the node version linter?

@jgehrcke
Copy link
Contributor Author

jgehrcke commented Aug 23, 2021

what code did you write that ran afoul of the node version linter?

Not sure if I really understand the question but I hope that the commit message of my last commit answers it. If it doesn't then I would appreciate clarification! :)

(maybe a tiny bit of clarification on top of the commit message: the new tests rely on process.hrtime.bigint() which has been introduced with NodeJS 10.7.0 -- and the lint tooling knows that -- and therefore emitted the error message shown in the commit message of the last commit here)

@JustinBeckwith JustinBeckwith merged commit e63ca08 into JustinBeckwith:main Aug 23, 2021
@github-actions
Copy link

🎉 This PR is included in version 2.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

vmatyus pushed a commit to IBM/couchbackup that referenced this pull request Nov 12, 2021
It introduced a delay between first attempt and first retry: JustinBeckwith/retry-axios#163
Therefore tests with retry takes more time then before. The longest run took 2s 33ms.
vmatyus pushed a commit to IBM/couchbackup that referenced this pull request Nov 12, 2021
It introduced a delay between first attempt and first retry: JustinBeckwith/retry-axios#163
Therefore tests with retry takes more time then before. The longest run took 2s 33ms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants