Skip to content

token refresh improvements #4281

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

Merged
merged 4 commits into from
May 28, 2025
Merged

token refresh improvements #4281

merged 4 commits into from
May 28, 2025

Conversation

wjordan
Copy link
Contributor

@wjordan wjordan commented Mar 28, 2025

Two changes to improve token-refresh behavior in the client:

  1. First try a Tokens.update without the UserURLCallback option (which can now fetch tokens in parallel), and then retry with the UserURLCallback option only if the first attempt returned any errors.
  2. Adjust the (now-configurable) advancePrune duration (from the default 1 minute) so the foreground thread has an advance-prune duration of 30 seconds while the background thread has 2 minutes. This should make it more likely for tokens to be refreshed in the background rather than delay foreground operations.

@wjordan wjordan requested a review from btoews March 28, 2025 23:18
Copy link
Contributor

@btoews btoews left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +193 to +196
updated, err := t.Update(ctx, updateOpts...)
if err == nil || !strings.Contains(err.Error(), "missing user-url callback") {
return updated, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment explaining that we can only parallelize if WithUserURLCallback is omitted might be useful. Without that knowledge it's confusing why we'd do it this way.

@wjordan wjordan merged commit 4d856df into master May 28, 2025
45 of 51 checks passed
@wjordan wjordan deleted the refresh-tokens-parallel branch May 28, 2025 23:05
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.

2 participants