-
Notifications
You must be signed in to change notification settings - Fork 294
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
Managed Identity Access Token is refreshed very often #1495
Comments
@kevinharing, a token should be refreshed in about 10 hours (5-10 minutes before expiration time) and it would be cached to make it easier to use. Is that happening sooner than that time for you? Even if a token is acquired manually when it goes to the pool when it is re-used (after 10 hours) server checks credentials and it may throw token the expired exception. |
A token should be refreshed 5-10 minutes before expiration time indeed (not 10 hours specifically as the token lifetime is configurable in AAD). As can be seen on the screenshots, this is happening way more often than once every 10 hours.
What do you mean with "server checks credentials"? A token does not contain credentials. |
A better term would be revalidation. We have a very good topic on this matter. It could be seen at #767 |
@kevinharing From our testing, the issue seems to be caused by the fact our local user didn't have a home directory (created with What we did was to simply remove the
Previously we saw thousands of such requests, which was slowing down a lot of our requests. |
With the upgrade to |
@scottaddie Are you recommending an explicit Update today with Managed Identity and the current version of MDS? |
@ErikEJ My recommendation is to use the v5.2.0 release of MDS when that becomes available. |
@kevinharing Have you tested with 5.2 preview 4 ? |
Nope, and to be frank, I currently don’t have time to test this out thoroughly. |
Any updates? I think it is still happening with MDS 5.2.0-preview5.24024.3. |
Hi @zheweiwangMicrosoft this will be targeted to be addressed by PR #2380, and you can give it a try with the pipeline's artifacts. |
@David-Engel @DavoudEshtehari did this fix make any release? |
@PaulVrugt It was added to 5.1.6 and 5.2.2 #2380 |
Describe the bug
I recently started using managed identity authentication functionality from SqlClient after using our own access token caching implementation, but I'm seeing a lot of random token refreshes and I'm wondering if this is expected. Below is a screenshot from app insights showing the refresh calls over a period of 24 hours of one app instance.
Before:
After:
I would expect the token to be cached around 24 hours before a refresh is triggered if the token lifetime is 24 hours. What I am experiencing though is that it refreshes at a seemingly random interval.
This behavior is slowing down a bunch of our requests as you can probably imagine.
One other thing I noticed is calls to the below endpoints when the token is refreshed. We did not see these pop up before the change.
Currently I'm considering moving back to our own implementation, because this is just plain dumb behavior.
To reproduce
Just run a application with using the below segment in the connection string.
Expected behavior
Refresh the token just before the token expires (5 minutes before or something).
Further technical details
Microsoft.Data.SqlClient version: 4.0.1
.NET target: 6.0.1
SQL Server version: Azure SQL Server
Operating system: aspnet:6.0-bullseye-slim
The text was updated successfully, but these errors were encountered: