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

NewConstant panics if the given base is zero #9

Closed
Deleplace opened this issue Jan 7, 2022 · 5 comments
Closed

NewConstant panics if the given base is zero #9

Deleplace opened this issue Jan 7, 2022 · 5 comments

Comments

@Deleplace
Copy link
Contributor

It seems to me that a zero Backoff makes sense, from a user POV who would just want to enjoy a retry facility.

Can we make 0 an accepted value for NewConstant?

Of course it is not difficult for a user to just call NewConstant(time.Nanosecond), but for flexibility I'm not sure we should advertise "zero delay" as a forbidden parameter.

Zero delays may already occur when using the API, as discussed in #8.

@sethvargo
Copy link
Owner

Hey @Deleplace - I'm really hesitant to do that because it creates a hot loop. The default behavior (without middleware) is to retry indefinitely. Thus retry.NewConstant(0) with a non-terminating condition would completely hog all CPU cores until OOM.

@Deleplace
Copy link
Contributor Author

Right, busy loops are not great.

The use cases I had in mind (network requests, DB requests, filesystem I/O) are so slow that they are self-throttled even without a delay between two attempts.

Now I realize that some use cases may indeed hog CPU/memory: whenever a resource is "not ready" and this information is in memory. E.g. "no network for now".

So, a zero backoff delay would be safe only when combined with flavors of WithMaxRetries, WithMaxDuration, WithJitter.

@sethvargo
Copy link
Owner

Even then, I think having a base like 10*time.Nanosecond is a good best practice.

@github-actions
Copy link

This issue is stale because it has been open for 14 days with no
activity. It will automatically close after 7 more days of inactivity.

@github-actions
Copy link

This issue has been automatically locked since there has not been any
recent activity after it was closed. Please open a new issue for
related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants