-
Notifications
You must be signed in to change notification settings - Fork 7.2k
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
ForEach-Object -Parallel Pipeline and other breakdowns #13588
Comments
Can you post the exact snippet you're using? I can't reproduce it.
Yeah classes aren't thread safe and are likely to cause deadlocks or state corruption. See #12801 |
I'll try to post something in the next day or so that replicates my logic. Classes not being thread safe should not matter. Each parallel execution dot sources the script containing the class definition. The code is written such that every parallel execution should not interact with another. |
Place in class.ps1
Place in testscript.ps1
Call Testscript.ps1 -Type ForEach Output:
Call Testscript.ps1 -Type Static Output:
Call Testscript.ps1 -Type Where Output:
Static, Where, and ForEach alll fail and foreachmethod works. |
And by "fail" I mean they sit there forever without doing anything, no error or indication of error |
Yeah, it's still the same generated type though. It's cached based on the AST which will be the same in all runspaces. You can see it by running this: $classFile = 'temp:\myClassFile.ps1'
try {
$null = New-Item -ItemType File -Path $classFile -Value 'class Testing { }'
$hashCodes = 0..100 | ForEach-Object -Parallel {
. $using:classFile
[Testing].GetHashCode()
}
$hashCodes | Group-Object
} finally {
Remove-Item $classFile -ErrorAction Ignore
} You should get something like this:
Though you might get a couple different on the first run if you hit a race condition, it should be mostly the same generated type. |
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
1 similar comment
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes. |
So, I know you are working on improving ForEach-Object -Parallel, but I wanted to offer what I have seen so far.
Within a ForEach-Object -Parallel, I load a script containing functions and class declarations. At some point within the processing, the pipeline breaks down first
something as simple as @() | Where-Object hangs indefinitely, while @().Where({}) executes fine. Further into the processing, even calling a static function of a defined PS class hangs indefinitely.
So far I've been working through the script trying to remove all Write-Progress calls (they intermittently causes hangs as well), Any Pipeline Where or ForEach calls, etc. But its odd now that even though breakpointing the script shows that the PS Class I created does exist, calling a static function hangs.
I know it would be impossible to provide enough context to help identify the issue, but I'm very confident that its not a breakdown in my code.
In addition to any insight you have, is there any way to see more about whats going on?
Thank you
I'm using the latest version of PS 7.
The text was updated successfully, but these errors were encountered: