Skip to content
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

Get-IshUser fails with 'Item has already been added. Key in dictionary: 'None' Key being added: 'None'' when running in parallel in StringEnum::GetStringValue #134

Closed
jlaridon opened this issue Sep 17, 2021 · 2 comments
Assignees
Milestone

Comments

@jlaridon
Copy link

jlaridon commented Sep 17, 2021

When running following script multiple times in parallel

$user = Get-IshUser -IshSession $session 
$userName = Get-IshMetadataField -IshObject $user -Name \"USERNAME\" 
return $userName"`

following error can occur

Message: "Item has already been added. Key in dictionary: 'None' Key being added: 'None'"
StackTrace:
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)\r\n
at System.Collections.Hashtable.Add(Object key, Object value)\r\n
at Trisoft.ISHRemote.HelperClasses.StringEnum.GetStringValue(Enum value)\r\n
at Trisoft.ISHRemote.Objects.Public.IshField.GetXml(XmlWriter& xmlWriter)\r\n
at Trisoft.ISHRemote.Objects.IshFields.GetXml(XmlWriter& xmlWriter)\r\n
at Trisoft.ISHRemote.Objects.IshFields.ToXml()\r\n
at Trisoft.ISHRemote.Cmdlets.User.GetIshUser.ProcessRecord()
@ddemeyer
Copy link
Contributor

Typically PowerShell is not multi-threaded unless you force it over Runspaces. In turn most of ISHRemote is thread-safe as cmdlets retrieve all their parameters from the outside. However, IshSession creation which is lean in the beginning, but as you ask/use it more it will keep a cache copy of the retrieved information. This issue is one of those, there is a static hashtable to speed up enum-conversion that happens numerously per cmdlet/API-call. The hashtable is created as we go by adding to it through StringEnum::GetStringValue

So either remove the (theoretical speedup) by removing the hashtable. Or make the hashtable threadsafe.

@ddemeyer ddemeyer changed the title Get-IshUser fails when running in parallel Get-IshUser fails with 'Item has already been added. Key in dictionary: 'None' Key being added: 'None'' when running in parallel in StringEnum::GetStringValue Sep 20, 2021
@ddemeyer ddemeyer added this to the v0.14 milestone Sep 20, 2021
@ddemeyer
Copy link
Contributor

Closes #134

ddemeyer pushed a commit that referenced this issue Sep 21, 2021
ddemeyer pushed a commit that referenced this issue Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants