[release/7.0] Ensure that OptionsCache only permits creating a single options instance per name #80150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #79529
Backport of #79639 to release/7.0
/cc @tarekgh @madelson
Customer Impact
When apps/services create multiple instances of
IOptionsMonitor<TestOptions>
concurrently at the starting time, it is possible to cause problems like throwing exceptionSystem.InvalidOperationException: Collection was modified; enumeration operation may not execute.
which cause the app or the service to fail to load or run. Such failure is reported from Azure AD in the issue AzureAD/microsoft-identity-web#1995. This is a regression from .NET 6.0 as a side effect of the change #79639.Testing
Added a regression test simulated the exact scenario and validated the desired behavior. Also, the change passed when running all regression tests.
Risk
Low, we didn't change any logic more than not calling the configuration callbacks when creating the entries cache and delay calling it after populating the cache and then calling it once.