-
Notifications
You must be signed in to change notification settings - Fork 594
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
OCPBUGS-29479: Add retries to async cache initialization #13610
Merged
openshift-merge-bot
merged 5 commits into
openshift:master
from
TheRealJon:OCPBUGS-29479
Feb 28, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
975cee7
OCPBUGS-29479: Add retries to async cache initialization
TheRealJon 6e153d8
Don't log errors on async cache retries.
TheRealJon 1a23fc3
Use context.WithTimeout and wait.UntilWithContext instead of a for lo…
TheRealJon 9761d5f
Use `wait.PollUntilContextTimeout` for async cache initialization
TheRealJon 5f03015
Address review comments
TheRealJon File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,12 @@ import ( | |
"k8s.io/klog" | ||
) | ||
|
||
const ( | ||
initializationRetryInterval = 30 * time.Second | ||
initializationTimeout = 5 * time.Minute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @deads2k is this ok? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
initializeImmediately = true | ||
) | ||
|
||
type cachingFuncType[T any] func(ctx context.Context) (T, error) | ||
|
||
type AsyncCache[T any] struct { | ||
|
@@ -27,13 +33,25 @@ func NewAsyncCache[T any](ctx context.Context, reloadPeriod time.Duration, cachi | |
cachingFunc: cachingFunc, | ||
} | ||
|
||
item, err := cachingFunc(ctx) | ||
err := wait.PollUntilContextTimeout( | ||
ctx, | ||
initializationRetryInterval, | ||
initializationTimeout, | ||
initializeImmediately, | ||
func(ctx context.Context) (bool, error) { | ||
item, err := cachingFunc(ctx) | ||
if err != nil { | ||
klog.V(4).Infof("failed to setup an async cache - retrying in %s", initializationRetryInterval) | ||
TheRealJon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false, err | ||
TheRealJon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
c.cachedItem = item | ||
return true, nil | ||
}, | ||
) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("failed to setup an async cache - caching func returned error: %w", err) | ||
} | ||
|
||
c.cachedItem = item | ||
|
||
return c, nil | ||
} | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about 10s to match the historical behavior:
console/pkg/auth/auth.go
Line 182 in 057e732