Title: Race condition exception when accessing $Host.UI.psobject.Properties inside a runspace · Issue #31 · PowerShell/ThreadJob · GitHub
Open Graph Title: Race condition exception when accessing $Host.UI.psobject.Properties inside a runspace · Issue #31 · PowerShell/ThreadJob
X Title: Race condition exception when accessing $Host.UI.psobject.Properties inside a runspace · Issue #31 · PowerShell/ThreadJob
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest version Search the existing issues. Steps to reproduce (thanks to Patrick Meinecke (@SeeminglyScience)) Environment: PowerShell 7.3.6 or higher on ...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest version Search the existing issues. Steps to reproduce (thanks to Patrick Meinecke (@SeeminglyScience)) Env...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest version Search the existing issues. Steps to reproduce (thanks to Patrick Meinecke (@SeeminglyScience)) Env...
Opengraph URL: https://github.com/PowerShell/ThreadJob/issues/31
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Race condition exception when accessing $Host.UI.psobject.Properties inside a runspace","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the latest version\r\n- [X] Search the existing issues.\r\n\r\n### Steps to reproduce (thanks to @SeeminglyScience)\r\n\r\n**Environment:**\r\n1. PowerShell 7.3.6 or higher on up-to-date Windows 10 22H2 x64\r\n3. ThreadJob 2.0.3 and Microsoft.PowerShell.ThreadJob 2.1.0\r\n\r\nSporadic race condition exception when accessing `$Host.UI.psobject.Properties` inside a runspace started with `Start-ThreadJob`:\r\n1. Start new session:\r\n`pwsh -nop`\r\n\r\n2. Paste following:\r\n```powershell\r\n$event = [System.Threading.ManualResetEvent]::new($false)\r\n$jobs = 1..500 | % {\r\n Start-ThreadJob {\r\n $event = $using:event\r\n $null = $event.WaitOne()\r\n $supportsVT = $Host.UI.psobject.Properties['SupportsVirtualTerminal'].Value\r\n } -StreamingHost $Host\r\n}\r\n\r\nStart-Sleep -Milliseconds 500\r\n$null = $event.Set()\r\n\r\n$jobs | Receive-Job -AutoRemoveJob -Wait\r\n```\r\n3. If you couldn't repro first time, start new PowerShell session, do not try in the same session.\r\n\r\n### Steps to reproduce with Pester 5.5.0:\r\n\r\n**Environment:**\r\n1. PowerShell 7.3.6 or higher on up-to-date Windows 10 22H2 x64\r\n2. Pester 5.5.0\r\n3. ThreadJob 2.0.3 and Microsoft.PowerShell.ThreadJob 2.1.0\r\n\r\nSporadic race condition exception when accessing `$Host.UI.psobject.Properties` inside a runspace started with `Start-ThreadJob`:\r\n1. Start new session:\r\n`pwsh -nop`\r\n\r\n2. Paste following:\r\n```powershell\r\n1..500 | ForEach-Object {\r\n Start-ThreadJob {\r\n 1 | Should -BeExactly 1\r\n $supportsVT = $Host.UI.psobject.Properties['SupportsVirtualTerminal'].Value\r\n } -StreamingHost $Host\r\n} | Wait-Job | Receive-Job | Remove-Job -Force\r\n```\r\n3. If you couldn't repro first time, start new PowerShell session, do not try in the same session.\r\n\r\n[More details here.](https://github.com/pester/Pester/issues/2383)\r\n\r\n### Expected behavior\r\n\r\n```console\r\nThere should be no exception.\r\n```\r\n\r\n\r\n### Actual behavior\r\n\r\n```console\r\nInvalidOperation: Cannot index into a null array.\r\nInvalidOperation: Cannot index into a null array.\r\nInvalidOperation: Cannot index into a null array.\r\nInvalidOperation: Cannot index into a null array.\r\n```\r\n\r\n\r\n### Error details\r\n\r\n```console\r\nPS C:\\> Get-Error\r\n\r\nException :\r\n Type : System.Management.Automation.RuntimeException\r\n ErrorRecord :\r\n Exception :\r\n Type : System.Management.Automation.ParentContainsErrorRecordException\r\n Message : Cannot index into a null array.\r\n HResult : -2146233087\r\n CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException\r\n FullyQualifiedErrorId : NullArray\r\n InvocationInfo :\r\n ScriptLineNumber : 1\r\n OffsetInLine : 26\r\n HistoryId : -1\r\n Line : 1 | Should -BeExactly 1; $supportsVT = $Host.UI.psobject.Properties['SupportsVirtualTerminal'].Value\r\n PositionMessage : At line:1 char:26\r\n + … eExactly 1; $supportsVT = $Host.UI.psobject.Properties['SupportsVirtu …\r\n + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n CommandOrigin : Internal\r\n ScriptStackTrace : at \u003cScriptBlock>, \u003cNo file>: line 1\r\n TargetSite : System.Object CallSite.Target(System.Runtime.CompilerServices.Closure, System.Runtime.CompilerServices.CallSite, System.Object, System.String)\r\n Message : Cannot index into a null array.\r\n Data : System.Collections.ListDictionaryInternal\r\n Source : Anonymously Hosted DynamicMethods Assembly\r\n HResult : -2146233087\r\n StackTrace :\r\n at CallSite.Target(Closure, CallSite, Object, String)\r\n at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)\r\n at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)\r\n at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)\r\nCategoryInfo : InvalidOperation: (:) [], RuntimeException\r\nFullyQualifiedErrorId : NullArray\r\nInvocationInfo :\r\n ScriptLineNumber : 1\r\n OffsetInLine : 26\r\n HistoryId : -1\r\n Line : 1 | Should -BeExactly 1; $supportsVT = $Host.UI.psobject.Properties['SupportsVirtualTerminal'].Value\r\n PositionMessage : At line:1 char:26\r\n + … eExactly 1; $supportsVT = $Host.UI.psobject.Properties['SupportsVirtu …\r\n + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n CommandOrigin : Internal\r\nScriptStackTrace : at \u003cScriptBlock>, \u003cNo file>: line 1\r\n```\r\n\r\n\r\n### Environment data\r\n\r\n```PowerShell\r\nName Value\r\n---- -----\r\nPSVersion 7.3.6\r\nPSEdition Core\r\nGitCommitId 7.3.6\r\nOS Microsoft Windows 10.0.19045\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n\r\n\r\n### Version\r\n\r\nThreadJob 2.0.3 and Microsoft.PowerShell.ThreadJob 2.1.0\r\n\r\n### Visuals\r\n\r\n\r\n","author":{"url":"https://github.com/kborowinski","@type":"Person","name":"kborowinski"},"datePublished":"2023-07-26T14:51:56Z","url":"https://github.com/PowerShell/ThreadJob/issues/31"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a99f2cb8-665d-2775-2f11-e24b3c0aefa7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B784:84384:3894DC:4C4336:6AFCD4C9 |
| html-safe-nonce | 80420a2ae247e9888e72e22033b279edb31e2399f4f3200f97b81efea6b50f44 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzg0Ojg0Mzg0OjM4OTREQzo0QzQzMzY6NkFGQ0Q0QzkiLCJ2aXNpdG9yX2lkIjoiNTYzMTU0ODc4NTE2NDA4MDMyOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4e87f08b188b6b8bc064a96f5405a82db47b7481d06a6b28faee43caf8b256bf |
| hovercard-subject-tag | issue:1822596170 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/ThreadJob/31/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cb9b7ee4f598b78f274eac9c1b992d5a21d93ae051a59bcbc5246df191ddc5d3/PowerShell/ThreadJob/issues/31 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cb9b7ee4f598b78f274eac9c1b992d5a21d93ae051a59bcbc5246df191ddc5d3/PowerShell/ThreadJob/issues/31 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest version Search the existing issues. Steps to reproduce (thanks to Patrick Meinecke (@SeeminglyScience)) Env... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kborowinski |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5b7bc7e41e0a604bbdb5035c7ed9620c2d28b9c8a18747182e2262a75abfd91 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/ThreadJob git https://github.com/PowerShell/ThreadJob.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 265675369 |
| octolytics-dimension-repository_nwo | PowerShell/ThreadJob |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 265675369 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/ThreadJob |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ff5022cc3aa767e6115451d9c322dd975506d40e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width