-
Notifications
You must be signed in to change notification settings - Fork 281
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
core/zero: fix ticker usage #4969
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I should also mention that a call to |
wasaga
requested changes
Feb 29, 2024
Sorry forgot I wasn't supposed to close PRs. Re-opening. |
wasaga
approved these changes
Mar 1, 2024
kenjenkins
pushed a commit
that referenced
this pull request
Mar 6, 2024
core/zero: fix ticker usage (#4969) Co-authored-by: Caleb Doxsey <cdoxsey@pomerium.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
In several places we use a
time.Ticker
based on abackoff.Backoff
. We create a newtime.Ticker
that fires immediately by using a short duration. Unfortunately this causes excessive CPU usage. There are several ways to fix this:backoff.NewTicker
function, which returns a "Ticker" that behaves as expected by using atime.Timer
instead. This approach does not work if we need to callReset
on theBackoff
.backoff.Retry
function with abackoff.WithContext
. We then don't need a timer or ticker.time.Ticker
we can use atime.Timer
set to the backoff interval. Since atime.Timer
is allowed to be set to 0 with no downside, this can handle the case when we want to fire immediately. The benefit over atime.After
is we can call.Stop
to collect resources if another case in the select fires.Option (3) was used for the
retry.Retry
function because the logic around resetting is incompatible with (1) and (2).Related issues
Fixes https://github.com/pomerium/internal/issues/1727
Checklist
improvement
/bug
/ etc)