vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

PSReadLine Errors cause prompt to loop endlessly

Open rfoust opened this issue 7 years ago • 6 comments

Environment data

PSReadline version: 2.0.0-beta4
os: Darwin Robbies-MBP 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64
PS file version: (the script sample didn't work, mac doesn't have a .exe)

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
6      2      0      preview.4       

Steps to reproduce or exception report

Enter the VS Code debugger, run a cmdlet in a module and have it stop at a breakpoint, then select the menu option Debug->Stop Debugging. Then PSReadline/Powershell goes into an endless loop displaying the following error:

Exception

System.Management.Automation.Runspaces.InvalidRunspaceStateException: Cannot invoke the pipeline because the runspace is not in the Opened state. Current state of the runspace is 'Closing'.
   at System.Management.Automation.Runspaces.RunspaceBase.AddToRunningPipelineList(PipelineBase pipeline)
   at System.Management.Automation.Runspaces.RunspaceBase.DoConcurrentCheckAndAddToRunningPipelines(PipelineBase pipeline, Boolean syncCall)
   at System.Management.Automation.Runspaces.PipelineBase.CoreInvoke(IEnumerable input, Boolean syncCall)
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.Runspaces.Pipeline.Invoke()
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKey()
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)

P> @
Oops, something went wrong. Please report this bug with the details below. Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new

Environment

PSReadLine: 2.0.0-beta3 PowerShell: 2.0.0 OS: Darwin 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 Last 200 Keys

 o r t - d u Backspace Backspace m o d u l e Spacebar d u a c c o u n t m a n a g e m e n t Spacebar - f o r c e Enter
 UpArrow UpArrow UpArrow UpArrow Enter
 UpArrow UpArrow Enter
 UpArrow UpArrow Enter
 $ t Enter
 $ t . t e n Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace i m p o r t m Backspace - m o d u l e Spacebar d u a c c o u n t n a Backspace Backspace m a n a t e m e n g Backspace Backspace Backspace Backspace Backspace Backspace g e m e n t Spacebar - f o r c e Enter
 g e t - d u u s e r Tab Spacebar r f o u s t Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 c Enter
 Ctrl+c @

Exception

System.Management.Automation.Runspaces.InvalidRunspaceStateException: Cannot invoke the pipeline because the runspace is not in the Opened state. Current state of the runspace is 'Closing'.
   at System.Management.Automation.Runspaces.RunspaceBase.AddToRunningPipelineList(PipelineBase pipeline)
   at System.Management.Automation.Runspaces.RunspaceBase.DoConcurrentCheckAndAddToRunningPipelines(PipelineBase pipeline, Boolean syncCall)
   at System.Management.Automation.Runspaces.PipelineBase.CoreInvoke(IEnumerable input, Boolean syncCall)
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.Runspaces.Pipeline.Invoke()
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKey()
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)

P> @

rfoust avatar Mar 28 '19 23:03 rfoust

I transferred this issue from the PSReadLine repo because this looks like a race condition where PSReadLine tries to use the Runspace when VSCode PowerShell debugging is using it. This seems related to #1965

/cc @TylerLeonhardt @rjmholt

daxian-dbw avatar Dec 19 '19 23:12 daxian-dbw

@rfoust Can you give this a go in the newer versions of the PowerShell Preview extension? It has a ton of fixes in it and it might be fixed in that already.

TylerLeonhardt avatar Dec 20 '19 00:12 TylerLeonhardt

I transferred this issue from the PSReadLine repo because this looks like a race condition where PSReadLine tries to use the Runspace when VSCode PowerShell debugging is using it. This seems related to #1965

/cc @TylerLeonhardt @rjmholt

FYI, this is just what it looks like whenever PSES crashes with PSRL. The runspace is closed during shutdown, but PSRL isn't properly stopped (or maybe is started again accidently) so it keeps trying to continue like normal, accessing a runspace that is not longer valid.

Hopefully a fix can be made to handle crashes gracefully again, this tends to cause a lot of confusion every time it comes up.

SeeminglyScience avatar Dec 20 '19 03:12 SeeminglyScience

This issue is being closed as inactive, if this issue is still occurring it will be re-opened

ghost avatar Jan 03 '20 06:01 ghost

This issue was closed automatically as repro info was indicated as needed, but there has been no activity in over a week. Please feel free to reopen with any available information!

ghost avatar Aug 19 '21 19:08 ghost

I know the bot auto-closed this due to age, but reading through the original issue, it may very well be fixed by the latest preview (going out today). I threaded through a cancellation token so that the debugger can stop more gracefully.

andyleejordan avatar Aug 19 '21 19:08 andyleejordan