azure-activedirectory-identitymodel-extensions-for-dotnet
azure-activedirectory-identitymodel-extensions-for-dotnet copied to clipboard
ConfigurationManager GetConfigurationAsync is often slow
Which version of Microsoft.IdentityModel are you using? Note that to get help, you need to run the latest version. Microsoft.IdentityModel.Protocols 7.5.2
Where is the issue?
- [x ] M.IM.Protocols.OpenIdConnect
Is this a new or an existing app? This is a new app or an experiment.
Repro
var wellKnownUri = "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration";
var configurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(
wellKnownUri, new OpenIdConnectConfigurationRetriever());
var openIdConfig = await configurationManager.GetConfigurationAsync();
Expected behavior
I would expect the call to GetConfigurationAsync() to be very fast.
Actual behavior
The call to GetConfigurationAsync() often takes 500ms or greater.
Additional context / logs / screenshots / links to code As this code is handling a large amount of requests from Microsoft Graph presence updates we need to be able to quickly process notifications and this one call is too slow. Part of processing the notification is validating the token that comes along with the request. This code is running in an Azure Linux Function App running on .net 8 isolated mode. I notice the issue in Azure or as well running locally from my machine with Visual Studio. I notice it hits https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration and https://login.microsoftonline.com/common/discovery/v2.0/keys and I can see with Fiddler that those endpoints return very quickly (less than 5 milliseconds each).
When I first started this app I was using version 7.2.0 of the package and upgraded to 7.5.2 and the performance was a little better but there still are cases of it being slow.
Are you sure you aren't using a sync over async pattern?
I don't believe I am. My entry point which is the Azure Function returns a Task<HttpResponseData> and the method I am calling GetConfigurationAsync from returns Task<bool>. (My function calls a method to check if the token is valid and the GetConfigurationAsync is called from that method)
@jsweiler Do you have any profile data by any chance? It would be very helpful to know where the time is being spent.
I'll try to get some and post my results.
Closing for now, feel free to re-open when you can provide a profile or more information