-
-
Notifications
You must be signed in to change notification settings - Fork 92
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
Server stops with errors "Collection was modified after..." #1257
Comments
It's a bug due to the way Powershell deals with array and piping. We have to make the Try this one Start-PodeServer {
Add-PodeEndpoint -Address localhost -Port 8081 -Protocol Http
#working
Add-PodeRoute -Path '/processes' -Method Get -ScriptBlock {
$r = Get-Process | .{ process { if ($_.WS -gt 100mb) { $_ } } } |
Select-Object Name, @{e = { [int]($_.WS / 1mb) }; n = 'WS' } |
Sort-Object WS -Descending
Write-PodeHtmlResponse -Value $r -StatusCode 200
}
#not working
Add-PodeRoute -Path '/processesPipedNotWorking' -Method Get -ScriptBlock {
Get-Process | .{ process { if ($_.WS -gt 100mb) { $_ } } } |
Select-Object Name, @{e = { [int]($_.WS / 1mb) }; n = 'WS' } |
Sort-Object WS -Descending | Write-PodeHtmlResponse -StatusCode 200
}
#this is like the previous one
Add-PodePage -Name NotWorkingProcesses -ScriptBlock {
Get-Process | .{ process { if ($_.WS -gt 100mb) { $_ } } } |
Select-Object Name, @{e = { [int]($_.WS / 1mb) }; n = 'WS' } |
Sort-Object WS -Descending
}
Start-Process http://localhost:8081/processes
} |
This was referenced Mar 25, 2024
Badgerati
added a commit
that referenced
this issue
Mar 29, 2024
Fix #1257 Collection was modified after..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the Bug
Server stops with the error "Collection was modified after the enumerator was instantiated."
Steps To Reproduce
Steps to reproduce the behavior:
2024-03-25-server-stops.zip
(1) Start the attached
server.ps1
, rather trivial one route server.(2) In the opened browser keep refreshing the page with brief processes details.
Alternatively, run the attached
loop.ps1
which sends similar requests in a loop.(3) At some point, sometimes soon or after a while, the server stops with errors like:
Errors may be at different locations and about different keys tested.
Expected Behavior
Ideally, the error should not happen, with its reasons avoided.
If this is not possible errors should be caught and ignored.
Platform
The text was updated successfully, but these errors were encountered: