Skip to content

Error on Integrated Console Start - PSInvalidOperationException Pipeline Issue #4048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
dgcode opened this issue Jun 26, 2022 · 16 comments · Fixed by PowerShell/PowerShellEditorServices#1918
Closed
3 tasks done
Assignees
Labels

Comments

@dgcode
Copy link

dgcode commented Jun 26, 2022

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

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.2.5
PowerShell: 2022.6.1
OS: Microsoft Windows 10.0.19044
BufferWidth: 196
BufferHeight: 22

Last 0 Keys:



### Exception

System.Management.Automation.PSInvalidOperationException: The pipeline was not run because a pipeline is already running. Pipelines cannot be run concurrently.
   at System.Management.Automation.Runspaces.PipelineBase.DoConcurrentCheck(Boolean syncCall, Object syncObject, Boolean isInLock)
   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.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   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[T](IEnumerable input, IList`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, PSInvocationSettings settings)
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear[TResult](PowerShell pwsh, PSInvocationSettings invocationSettings) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 76
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeCommand[TResult](PowerShell pwsh, PSCommand psCommand, PSInvocationSettings invocationSettings) in 
D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 99
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask`1.ExecuteNormally(CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousPowerShellTask.cs:line 119
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask`1.Run(CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousPowerShellTask.cs:line 70
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask`1.ExecuteSynchronously(CancellationToken executorCancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousTask.cs:line 92
--- End of stack trace from previous location ---
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask`1.get_Result() in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousTask.cs:line 58
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask`1.ExecuteAndGetResult(CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousTask.cs:line 108
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.InvokePSCommand[TResult](PSCommand psCommand, PowerShellExecutionOptions executionOptions, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 432
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.InvokePSCommand(PSCommand psCommand, PowerShellExecutionOptions executionOptions, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 435
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.OnPowerShellIdle(CancellationToken idleCancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 1078
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKey()
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)

Screenshot

image

Environment data

PS Version: 7.2.5
PS HostName: Visual Studio Code Host
PSReadLine Version: 2.2.5
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 121
BufferHeight: 65

Steps to reproduce

  • Start VS Code
  • Open a PowerShell script/launch the integrated console

Expected behavior

  • Console should start with no issues

Actual behavior

  • Console continuously spits out the stated error
  • Regular commands can be run without issue
@ghost ghost added the Needs-Triage 🔍 label Jun 26, 2022
@dgcode
Copy link
Author

dgcode commented Jun 26, 2022

Additional context:

  • Issue only occurs when using the PowerShell plugin in VS Code since version v2022.5.1
  • I am using latest version Oh My Posh

I am not sure that this is an issue with PSReadLine or the PowerShell plugin in VS Code. Please let me know if you want me to migrate this issue to their repo.

@daxian-dbw daxian-dbw transferred this issue from PowerShell/PSReadLine Jun 27, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Jun 27, 2022
@andyleejordan
Copy link
Member

What happens if you load without profiles?

@andyleejordan andyleejordan added Needs: Author Feedback Please give us the requested feedback! Issue-Bug A bug to squash. and removed Needs: Triage Maintainer attention needed! Needs-Triage 🔍 labels Jun 27, 2022
@dgcode
Copy link
Author

dgcode commented Jun 27, 2022

The terminal loads without issue.

Following this thread further, I narrowed down the issue to the following:

# Attempt to load and start Az Predictor
try {
    if ($PSVersionTable.PSVersion.Major -gt 5) {
        Import-Module Az.Tools.Predictor
        Set-PSReadLineOption -PredictionSource History
    }
}
catch {
    Write-Warning "An Error occurred loading Az Predictor: $($Error[0].Exception.Message)" 
}

Since these specific cmdlets were from when Az.Tools.Predictor was in preview, I thought I'd check the documentation and can see that they recommend a different approach to starting it:

# Attempt to load and start Az Predictor
try {
    if ($PSVersionTable.PSVersion.Major -gt 5) {
        Enable-AzPredictor -AllSession
        Set-PSReadLineOption -PredictionViewStyle InlineView
    }
}
catch {
    Write-Warning "An Error occurred loading Az Predictor: $($Error[0].Exception.Message)" 
}

Tried this which resulted in the same error.

@ghost ghost added Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Author Feedback Please give us the requested feedback! labels Jun 27, 2022
@andyleejordan
Copy link
Member

andyleejordan commented Jun 27, 2022

Try taking out the Write-Warning. I have a hunch that won't work in a profile on startup of the extension. (I don't know what I was thinking here.)

@dgcode
Copy link
Author

dgcode commented Jun 27, 2022

Can confirm that even with a Write-Host, it still errors:
image

And with no exception handling:
image

@andyleejordan
Copy link
Member

How about narrowing it down between: Import-Module Az.Tools.Predictor and Set-PSReadLineOption -PredictionViewStyle InlineView?

@SydneyhSmith SydneyhSmith added Needs: Repro Info 🤔 and removed Needs: Maintainer Attention Maintainer attention needed! labels Jun 28, 2022
@dgcode
Copy link
Author

dgcode commented Jun 29, 2022

With just those two lines in the profile, I still get the issue on version 2022.5.0 and above:
image

@dgcode
Copy link
Author

dgcode commented Jun 29, 2022

Details on the version of Az.Tools.Predictor I am using in case it's helpful:
image

@andyleejordan
Copy link
Member

I think you'll need to not import Az.Tools.Predictor when your host is the PSIC, seems broken.

@andyleejordan
Copy link
Member

Or set [Microsoft.Azure.PowerShell.Tools.AzPredictor.AzPredictorData]::ShowSurveyOnIdle = $False?

@andyleejordan
Copy link
Member

Sounds like @SeeminglyScience might have a fix.

@ghost
Copy link

ghost commented Jul 7, 2022

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 ghost closed this as completed Jul 7, 2022
@dgcode
Copy link
Author

dgcode commented Jul 7, 2022

Re-opening, have already provided repro info.

@SeeminglyScience SeeminglyScience moved this to In Progress in American Pharoah Jul 8, 2022
@andyleejordan
Copy link
Member

Idea from Patrick: "When we create the initial PowerShell instance, we need to mark it as nested with RunspaceMode.CurrentRunspace. Will probably through an exception, will need to temporarily set a default runspace while we mark it as nested." Currently being done elsewhere in the code. In most cases we don't use the initial instance. Because this is being loaded in the profile specifically, it's hitting an OnIdle run before we've ran something else, hence using the non-nested runspace and failing.

@andyleejordan
Copy link
Member

@dgcode I think I have a fix, I need to have @SeeminglyScience review it and then we'll test it with you in Preview.

@dgcode
Copy link
Author

dgcode commented Sep 13, 2022

Sounds good, cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants