Skip to content

Potential ThreadSafe issue #1601

@MarkDordoy

Description

@MarkDordoy

I run some powershell that interacts with MS graph in parallel processes (using the built in pwsh foreach-object -parallel workflow).

I was using module version 1.9.3 without issue. I attempted to update to 1.14.0 and I started getting errors as shown below:

DEBUG: [CmdletEndProcessing]: - Get-MgGroupMember end processing.
DEBUG: [CmdletEndProcessing]: - Get-MgGroupMember end processing.
DEBUG: [CmdletBeginProcessing]: - Get-MgGroupMember begin processing with parameterSet 'List1'.
DEBUG: [Authentication]: - AuthType: 'AppOnly', AuthProviderType: 'ClientCredentialProvider', ContextScope: 'Process', AppName: 'mdordoy-dev-app '.
DEBUG: [Authentication]: - Scopes: [Group.Read.All, EntitlementManagement.Read.All, User.Read.All, GroupMember.Read.All].
DEBUG: [CmdletException]: Received exception with message 'InvalidOperationException - Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct. :    at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
   at System.Net.Http.Headers.HttpHeaders.TryGetAndParseHeaderInfo(HeaderDescriptor key, HeaderStoreItemInfo& info)
   at Microsoft.Graph.PowerShell.Authentication.Helpers.HttpHelpers.GetGraphHttpClient(InvocationInfo invocationInfo, IAuthContext authContext)
   at Microsoft.Graph.PowerShell.Module.BeforeCreatePipeline(InvocationInfo invocationInfo, HttpPipeline& pipeline)
   at Microsoft.Graph.PowerShell.Module.CreatePipeline(InvocationInfo invocationInfo, String parameterSetName)
   at Microsoft.Graph.PowerShell.Cmdlets.GetMgGroupMember_List1.ProcessRecordAsync()'
DEBUG: [CmdletBeginProcessing]: - Get-MgGroupMember begin processing with parameterSet 'List1'.
DEBUG: [Authentication]: - AuthType: 'AppOnly', AuthProviderType: 'ClientCredentialProvider', ContextScope: 'Process', AppName: 'mdordoy-dev-app '.
DEBUG: [Authentication]: - Scopes: [Group.Read.All, EntitlementManagement.Read.All, User.Read.All, GroupMember.Read.All].
DEBUG: [CmdletException]: Received exception with message 'InvalidOperationException - Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct. :    at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
   at System.Net.Http.Headers.HttpHeaders.TryGetAndParseHeaderInfo(HeaderDescriptor key, HeaderStoreItemInfo& info)
   at Microsoft.Graph.PowerShell.Authentication.Helpers.HttpHelpers.GetGraphHttpClient(InvocationInfo invocationInfo, IAuthContext authContext)
   at Microsoft.Graph.PowerShell.Module.BeforeCreatePipeline(InvocationInfo invocationInfo, HttpPipeline& pipeline)
   at Microsoft.Graph.PowerShell.Module.CreatePipeline(InvocationInfo invocationInfo, String parameterSetName)
   at Microsoft.Graph.PowerShell.Cmdlets.GetMgGroupMember_List1.ProcessRecordAsync()'

If i run the script slower, will less threads processing at one, i have this happen much less. If I throttle at 1 thread at a time, the issue goes away.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions