Open AnatoliB opened 2 weeks ago
Transferred from common repo -
Thanks a lot for @AnatoliB 's investigation! The RCA makes a lot of sense since considering that the writeWaring key is frequently read and written. I'll try if we can snug this bug fix in the major release.
Here is the current implementation: https://github.com/Azure/azure-powershell-common/blob/ae44bad385cacd80cdf252d0be6a519b97486dd8/src/Authentication.Abstractions/AzureSession.cs#L214
Even though a
ConcurrentDictionary
is used for_componentRegistry
, line 220 can still throwKeyNotFoundException
if the collection is changed after invokingContainsKey
(line 218) but before invoking[]
(line 220), which I believe is not intentional.I recommend invoking
_componentRegistry.TryGetValue
instead.It may be hard to reproduce this because very precise timing is required, but it actually happens when used at scale (for example, in the context of Azure Functions). A typical exception surfaced to PowerShell code looks like this: