Title: Background jobs (`Start-Job`) and `ForEach-Object -AsJob -Parallel`, in combination with `Debug-Job`, prematurely report being in the `Running` state, before being ready for debugging · Issue #21258 · PowerShell/PowerShell · GitHub
Open Graph Title: Background jobs (`Start-Job`) and `ForEach-Object -AsJob -Parallel`, in combination with `Debug-Job`, prematurely report being in the `Running` state, before being ready for debugging · Issue #21258 · PowerShell/PowerShell
X Title: Background jobs (`Start-Job`) and `ForEach-Object -AsJob -Parallel`, in combination with `Debug-Job`, prematurely report being in the `Running` state, before being ready for debugging · Issue #21258 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/21258
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Background jobs (`Start-Job`) and `ForEach-Object -AsJob -Parallel`, in combination with `Debug-Job`, prematurely report being in the `Running` state, before being ready for debugging","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 released version](https://github.com/PowerShell/PowerShell/releases)\r\n- [X] Search the existing issues.\r\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\r\n\r\n### Steps to reproduce\r\n\r\nNote: _Thread_ jobs (`Start-ThreadJob`) are _not_ affected (although for them too it must be manually ensured that the job is in the `Running` state). Curiously, though, the technologically closely related `ForEach-Object -AsJob -Parallel` _is_ affected too.\r\n\r\n* `Debug-Job` requires a job to be in the `Running` (or `AtBreakPoint`) state in order for debugger invocation to succeed.\r\n* On startup, background jobs (`Start-Job`) report `Running` earlier than expected, causing `Debug-Job` to fail.\r\n\r\n```powershell\r\n$jb = Start-Job {\r\n while ($true) { Start-Sleep -Milliseconds 100 }\r\n}\r\n\r\ntry {\r\n\r\n Write-Verbose -Verbose 'Waiting for job to be in the ''Running'' state...'\r\n while ($jb.State -notin 'Running') { Start-Sleep -Milliseconds 100 }\r\n\r\n # If you enable this, the call works.\r\n # Start-Sleep -Milliseconds 500\r\n\r\n Write-Verbose -Verbose 'Starting debugging...'\r\n $jb | Debug-Job\r\n\r\n}\r\nfinally {\r\n if ($jb) { $jb | Remove-Job -Force }\r\n}\r\n```\r\n\r\n\r\n### Expected behavior\r\n\r\n```console\r\nThe debugger should be entered.\r\n```\r\n\r\n\r\n### Actual behavior\r\n\r\n`Debug-Job` fails with the following error:\r\n\r\n```console\r\nDebug-Job: /Users/jdoe/script.ps1:10\r\nLine |\r\n 274 | $jb | Debug-Job\r\n | ~~~~~~~~~\r\n | The provided job and all child jobs were examined but no jobs were found that could be debugged. In order to debug a job or child job the job must support debugging and\r\n | also be in a running state.\r\n```\r\n\r\nNote that if you introduce an artificial delay (uncomment the `Start-Sleep` statement in the code), things work as expected.\r\n\r\n### Error details\r\n\r\n```console\r\nException :\r\n Type : System.Management.Automation.PSInvalidOperationException\r\n ErrorRecord :\r\n Exception :\r\n Type : System.Management.Automation.ParentContainsErrorRecordException\r\n Message : The provided job and all child jobs were examined but no jobs were found that could be debugged. In order to debug a job or child job the job must support\r\ndebugging and also be in a running state.\r\n HResult : -2146233087\r\n CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException\r\n FullyQualifiedErrorId : InvalidOperation\r\n TargetSite :\r\n Name : ThrowTerminatingError\r\n DeclaringType : System.Management.Automation.MshCommandRuntime, System.Management.Automation, Version=7.5.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35\r\n MemberType : Method\r\n Module : System.Management.Automation.dll\r\n Message : The provided job and all child jobs were examined but no jobs were found that could be debugged. In order to debug a job or child job the job must support\r\ndebugging and also be in a running state.\r\n Source : System.Management.Automation\r\n HResult : -2146233079\r\n StackTrace :\r\n at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)\r\nTargetObject : Microsoft.PowerShell.Commands.DebugJobCommand\r\nCategoryInfo : InvalidOperation: (Microsoft.PowerShel…nds.DebugJobCommand:DebugJobCommand) [Debug-Job], PSInvalidOperationException\r\nFullyQualifiedErrorId : DebugJobNoDebuggableJobsFound,Microsoft.PowerShell.Commands.DebugJobCommand\r\nInvocationInfo :\r\n MyCommand : Debug-Job\r\n ScriptLineNumber : 274\r\n OffsetInLine : 9\r\n HistoryId : 2\r\n ScriptName : /Users/jdoe/script.ps1\r\n Line : $jb | Debug-Job\r\n\r\n Statement : Debug-Job\r\n PositionMessage : At /Users/jdoe/script.ps1:10 char:9\r\n + $jb | Debug-Job\r\n + ~~~~~~~~~\r\n PSScriptRoot : /Users/jdoe\r\n PSCommandPath : /Users/jdoe/script.ps1\r\n InvocationName : Debug-Job\r\n CommandOrigin : Internal\r\nScriptStackTrace : at \u003cScriptBlock>, /Users/jdoe/script.ps1: line 10\r\n at \u003cScriptBlock>, \u003cNo file>: line 1\r\n```\r\n\r\n\r\n### Environment data\r\n\r\n```powershell\r\nPowerShell 7.5.0-preview.1\r\n```\r\n\r\n\r\n### Visuals\r\n\r\n_No response_","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2024-02-21T22:43:52Z","url":"https://github.com/PowerShell/PowerShell/issues/21258"}
| 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:1c71625e-0f2a-d01d-b6cd-7030bfbc56a9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B894:3162A4:1091C6:15F3E1:6AFD0E63 |
| html-safe-nonce | 7b4bccf902ebf4fde85cbb36c35df859cc7978eee2f432043cba6bc3544b6039 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODk0OjMxNjJBNDoxMDkxQzY6MTVGM0UxOjZBRkQwRTYzIiwidmlzaXRvcl9pZCI6Ijg4NjAxNzI2Mzg5NzkxNjU3OTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b83b162959139fdc509c84687729fc549ce8e251294fe8fbf378505e738d2b96 |
| hovercard-subject-tag | issue:2147838901 |
| 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/PowerShell/21258/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1f9b2902a3c5931c94122179f0fef2203e6db59a3d9ac4a4f38e554586a16034/PowerShell/PowerShell/issues/21258 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1f9b2902a3c5931c94122179f0fef2203e6db59a3d9ac4a4f38e554586a16034/PowerShell/PowerShell/issues/21258 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b29de2abb97b6307b16270785efeb58b51a117d5a9b659acf00b77aa00e7043b |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| 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 | 8c9e619def6d670dc18a45d3b02cea938c1c7e47 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width