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

improve token refresh logic #277

Merged
merged 5 commits into from
Nov 22, 2021

Conversation

yunhaoling
Copy link
Contributor

@yunhaoling yunhaoling commented Sep 29, 2021

addressing issue: Azure/azure-sdk-for-python#20573

The improvements include:

  • allow override refresh window
    • resolve the refresh windows gap between current uamqp setting (6 mins) and AAD service (5 mins)
      • the AAD service returns a cached token, the service side refresh the token until 5 mins before expiration
  • not to put an old token onto the cbs link
    • avoid throttling SB/EH service
    • avoid potentially blocking handler work while token is still valid but about to be expired

TODO:

  • step1: discuss with anna on the fix/design
    • should override_... be a public parameter?
  • step2: add tests

There's one more improvement I could think of, introducing backoff when calling "update_token" if the newly-generated token is the same as old one to avoid throttling token generation module/service, but I'm afraid that goes too far for now.

@yunhaoling yunhaoling marked this pull request as ready for review October 5, 2021 00:08
_logger.info(
"The newly acquired token on connection %r is the same as the previous one,"
" will keep attempting to refresh",
self._connection.container_id
Copy link
Member

Choose a reason for hiding this comment

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

Is this log statement going to get very noisy? Or is it very rare that token == previous_token after calling update_token?

Copy link
Contributor Author

@yunhaoling yunhaoling Oct 12, 2021

Choose a reason for hiding this comment

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

yes, it would be very noisy in the case token == previous_token (which happens now when there's a gap between the client refresh window (uAMQP 6 mins to refresh) and service refresh window (AAD service 5 mins refresh))

So once we have fixed the issue in uamqp/eh/sb, changing default refresh window to 5 mins, it should be rare -- at least not worse than what we currently have.


I think what uamqp is doing technically is not wrong -- it's doing its best to refresh token, however it's doing a bit excessively, retry without backoff. So ultimately we might want to introduce kinda backoff to token refresh to let it not throttle.

with that being said, I think we could keep this "potential" noisy logging for now until user complains.

uamqp/authentication/cbs_auth.py Outdated Show resolved Hide resolved
@yunhaoling yunhaoling requested a review from annatisch October 13, 2021 00:38
@yunhaoling yunhaoling merged commit ca2df94 into Azure:master Nov 22, 2021
@yunhaoling yunhaoling deleted the improve-token-refresh branch November 22, 2021 18:52
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