AzureSession.TryGetComponent throws KeyNotFoundException when AzureSession is used concurrently #26624
Labels
Azure PS Team
bug
This issue requires a change to an existing behavior in the product in order to be resolved.
Tracking
We will track status and follow internally
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:
The text was updated successfully, but these errors were encountered: