Skip to content

Using Debug-Job to debug a background / thread job causes a crash #3954

@mklement0

Description

@mklement0

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

VERBOSE: Waiting for job to be in the 'Running' state...
VERBOSE: Starting debugging...
At line:2 char:10
+   while ($true) { Start-Sleep -Milliseconds 100 }
+          ~~~~~
[DBG]: [Job12]: PS /Users/jdoe>>
Oops, something went wrong.
Please report this bug with ALL the details below, including both the 'Environment' and 'Exception' sections.
Please report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new?template=Bug_Report.yaml
Thank you!

### Environment
PSReadLine: 2.3.4
PowerShell: 7.5.0-preview.1
OS: Darwin 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000
BufferWidth: 180
BufferHeight: 60

Last 33 Keys:

 p g Enter
 p g Enter
 p g Enter
 p g Enter
 g j b Enter
 g m o Enter
 p g Enter
 p g Enter
 c l r Enter
 p g Enter


### Exception

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.PowerShell.PSConsoleReadLine.UpdatePredictionClient(Runspace runspace, EngineIntrinsics engineIntrinsics)
   at Microsoft.PowerShell.PSConsoleReadLine.Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)

Screenshot

N/A

Environment data

PS Version: 7.5.0-preview.1
PS HostName: ConsoleHost
PSReadLine Version: 2.3.4
PSReadLine EditMode: Emacs
OS: Darwin SomeMachine.local 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000 arm64
BufferWidth: 180
BufferHeight: 60

Steps to reproduce

$jb = Start-ThreadJob {
  while ($true) { Start-Sleep -Milliseconds 100 }
}

try {

  Write-Verbose -Verbose 'Waiting for job to be in the ''Running'' state...'
  while ($jb.State -notin  'Running') { Start-Sleep -Milliseconds 100 }

  Write-Verbose -Verbose 'Starting debugging...'
  $jb | Debug-Job

}
finally {
  if ($jb) { $jb | Remove-Job -Force }
}

Expected behavior

The debugger should be entered and behave normally.

Actual behavior

PSReadLine crashes with the output above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIt either shouldn't be doing this or needs an investigation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions