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

Avoid passing undefined through to async-retry, remove maxTries option #306

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lencioni
Copy link
Contributor

@lencioni lencioni commented Feb 6, 2025

The makeRequest function accepts some options that default to undefined when they are not specified. These are then passed into async-retry, which eventually gets merged into the default options in a loop like this:

for (var key in options) {
  opts[key] = options[key];
}

https://github.com/tim-kos/node-retry/blob/11efd6e4/lib/retry.js#L17-L26

This means that when the options are not specified, they end up overriding the reasonable defaults, which was unintentional.

The result is that since we don't specify these options most of the time, most of the requests will be retried immediately instead of waiting a little bit.

To fix this, we need to construct the options a little more carefully.

I wanted to test this using jest fake timers, but when I did that it caused the tests to stall out and I wasn't able to figure out why in a reasonable amount of time, so instead I decided that it was okay for the test to take a second and just set the number of retries to a low amount.

While I am touching this, I decided to also simplify the API a small amount by removing a really old leacy maxTries option.

The makeRequest function accepts some options that default to undefined
when they are not specified. These are then passed into async-retry,
which eventually gets merged into the default options in a loop like
this:

```js
for (var key in options) {
  opts[key] = options[key];
}
```

https://github.com/tim-kos/node-retry/blob/11efd6e4/lib/retry.js#L17-L26

This means that when the options are not specified, they end up
overriding the reasonable defaults, which was unintentional.

The result is that since we don't specify these options most of the
time, most of the requests will be retried immediately instead of
waiting a little bit.

To fix this, we need to construct the options a little more carefully.

I wanted to test this using jest fake timers, but when I did that it
caused the tests to stall out and I wasn't able to figure out why in a
reasonable amount of time, so instead I decided that it was okay for the
test to take a second and just set the number of retries to a low
amount.

While I am touching this, I decided to also simplify the API a small
amount by removing a really old leacy `maxTries` option.
@lencioni lencioni requested a review from trotzig February 6, 2025 21:47
The signed variable doesn't change between retries, so we can just
generate it once instead of on each retry. This makes the code a bit
more efficient.
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

Successfully merging this pull request may close these issues.

1 participant