Badgerati / Pode

Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
https://badgerati.github.io/Pode
MIT License
866 stars 92 forks source link

Sessions clean-up housekeeper can throw "collection modified" error #1408

Closed Badgerati closed 1 month ago

Badgerati commented 1 month ago

Describe the Bug

When sessions are enabled, you can sometimes periodically see the following error in the terminal/logs:

Date: 2024-10-06 15:20:00
Level: Error
ThreadId: 0
Server: DESKTOP-900K9L3
Category: OperationStopped: (:) [Invoke-PodeScriptBlock], InvalidOperationException
Message: Collection was modified; enumeration operation may not execute.
StackTrace: at <ScriptBlock>, C:\...\PowerShell\Modules\Pode\2.11.0\Private\Sessions.ps1: line 293
at Invoke-PodeScriptBlock, C:\...\PowerShell\Modules\Pode\2.11.0\Public\Utilities.ps1: line 573
at <ScriptBlock>, <No file>: line 57

This is being thrown by the following line, and the Keys needs a .Clone() adding:

foreach ($key in $store.Memory.Keys) {

Note: This isn't a new error, my guess is this has been occurring for a long time. With the added error handling and better visibility for Schedules added in 2.11.0 this is why it's cropping up now.

Platform