-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Regression in Microsoft.Extensions.Options when IOptionsMonitor<T> created concurrently #79529
Comments
Tagging subscribers to this area: @dotnet/area-extensions-options Issue DetailsDescriptionv7 has introduced a change in behaviour when the first creation of an Given configuration code like this:
In dotnet 6 you could create multiple instances of In dotnet 7, the same operation results in multiple calls to the configuration callback. This was originally noticed as configuration of Microsoft.Identity.Web authentication stopped working correctly post upgrade to dotnet 7. I raised a ticket there (AzureAD/microsoft-identity-web#1995), but it was then narrowed down to be a Microsoft.Extensions.Options problem instead, so raising ticket here as @Tratcher suggested. Reproduction Stepshttps://github.com/petedishman/OptionsTest contains a reproduction of this problem with two identical projects, except one is configured with the v6 versions of the libraries, and the other with v7. The code sets up configuration as above, and then creates (concurrently) multiple instances of a service that take When run against v6 libraries you get this output:
When run against v7, you get this:
After the initial concurrent access, subsequent calls to inject an Expected behaviorThe configuration callback should only be executed when multiple instances are requested concurrently Actual behaviorThe configuration callback is called multiple times when initialised many times concurrently Regression?Yes - regression since v6 #66688 seems likely to be related/the cause Known WorkaroundsInitialising the ConfigurationTested on .net 6 & 7 running on both windows & linux x64. Does not appear to be platform specific. Other informationNo response
|
…nce per name. This incurs an extra delegate allocation, but only on instance creation. fix dotnet#79529
@tarekgh is this a patch candidate? It's a regression that's causing issues in production. |
Re-opening per #79529 (comment). @dotnet/area-extensions-options |
@petedishman @tratacher could you please elaborate more about the exact problem that happened in the production? I know the callback will be called multiple times, but what exactly the side effect with that that break the production? |
This issue has been marked |
See AzureAD/microsoft-identity-web#1995 where this caused the options instance to be mis-configured such that OIDC events are called multiple times for the same request. These events aren't expecting that and can fail. |
Yes we should patch this one. |
I'll start the patch process early next year when I am back. I already marked the issue with the 7.0 milestone. @petedishman is there a way to try the fix #79639 in your environment to validate the fix? |
…nce per name. This incurs an extra delegate allocation, but only on instance creation. fix #79529
… options instance per name (#80150) * Ensure that OptionsCache only permits creating a single options instance per name. This incurs an extra delegate allocation, but only on instance creation. fix #79529 * Ignore test on browser * Add Servicing elements Co-authored-by: Michael Adelson <mike.adelson314@gmail.com> Co-authored-by: Tarek Mahmoud Sayed <tarekms@microsoft.com>
This has been ported to the 7.0 servicing release branch though the PR #80150. |
Description
v7 has introduced a change in behaviour when the first creation of an
IOptionMonitor<T>
instance is done many times concurrently.Given configuration code like this:
In dotnet 6 you could create multiple instances of
IOptionsMonitor<TestOptions>
concurrently on startup and the configuration callback would only be called once.In dotnet 7, the same operation results in multiple calls to the configuration callback.
This was originally noticed as configuration of Microsoft.Identity.Web authentication stopped working correctly post upgrade to dotnet 7.
I raised a ticket there (AzureAD/microsoft-identity-web#1995), but it was then narrowed down to be a Microsoft.Extensions.Options problem instead, so raising ticket here as @Tratcher suggested.
Reproduction Steps
https://github.com/petedishman/OptionsTest contains a reproduction of this problem with two identical projects, except one is configured with the v6 versions of the libraries, and the other with v7.
The code sets up configuration as above, and then creates (concurrently) multiple instances of a service that take
IOptionsMonitor<TestOptions>
as a dependency.When run against v6 libraries you get this output:
When run against v7, you get this:
After the initial concurrent access, subsequent calls to inject an
IOptionsMonitor<TestOptions>
instance correctly don't re-run the configuration callback.Expected behavior
The configuration callback should only be executed when multiple instances are requested concurrently
Actual behavior
The configuration callback is called multiple times when initialised many times concurrently
Regression?
Yes - regression since v6
#66688 seems likely to be related/the cause
Known Workarounds
Initialising the
IOptionsMonitor<T>
instance once manually before any possible concurrent access works around the problem.Configuration
Tested on .net 6 & 7 running on both windows & linux x64. Does not appear to be platform specific.
Other information
No response
The text was updated successfully, but these errors were encountered: