Skip to content

PowerShell Extension terminal hangs when using Windows PowerShell #4731

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
6 tasks done
sba923 opened this issue Sep 7, 2023 · 25 comments
Closed
6 tasks done

PowerShell Extension terminal hangs when using Windows PowerShell #4731

sba923 opened this issue Sep 7, 2023 · 25 comments
Labels
Issue-Bug A bug to squash.

Comments

@sba923
Copy link

sba923 commented Sep 7, 2023

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

While investigating another issue I switched to "Windows PowerShell (x64)" in the "PowerShell Session Menu."

Now the session doesn't start anymore, it hangs at:

PowerShell Extension v2023.6.0
Copyright (c) Microsoft Corporation.

https://aka.ms/vscode-powershell
Type 'help' to get help.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      5.1.19041.3031
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.3031
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

(assumed, given that I can't get that PowerShell version to run within VScode)

Visual Studio Code Version

1.81.1
6c3e3dba23e8fadc360aed75ce363ba185c49794
x64

Extension Version

Steps to Reproduce

  1. switch to "Windows PowerShell (x64)" via the PowerShell Session Menu (resulting in powershell.powerShellDefaultVersion being set to Windows PowerShell (x64).
  2. A "session restart" occurs
  3. The session never finishes initializing

When powershell.powerShellDefaultVersion is set to PowerShell (x64) the problem goes away.

(I know support for Windows PowerShell 5.1 is "best effort")

Visuals

No response

Logs

169408~1.ZIP

@sba923 sba923 added the Issue-Bug A bug to squash. label Sep 7, 2023
@SydneyhSmith
Copy link
Collaborator

Thanks @sba923 it looks like it having issues at the loading profile step, do you have anything in your profile? does it work without a profile?

@sba923
Copy link
Author

sba923 commented Sep 14, 2023

My $profile.CurrentUserAllHosts contains one line, sourcing my actual profile.ps1 that resides elsewhere (and is 1,004 lines long 🙃).

If that comment out that line, the problem remains.

@sba923
Copy link
Author

sba923 commented Oct 6, 2023

I can repro this on another machine...

@andyleejordan
Copy link
Member

Have you tried with powershell.enableProfileLoading to completely rule it out?

@sba923
Copy link
Author

sba923 commented Oct 11, 2023

Not yet... but... I hate to say... I can't seem to repro the issue right now... I'll keep trying...

@sba923
Copy link
Author

sba923 commented Oct 28, 2023

I confirm the extension doesn't hang anymore, but it's unusable due to something that looks related to PSReadLine:

image

@andyleejordan
Copy link
Member

What custom key handlers do you have set, can you run it without them?

@sba923
Copy link
Author

sba923 commented Nov 1, 2023

I've found the culprit, and it's not PSReadLine-related.

Wrapping the loading of oh-my-posh within

if (($PSVersionTable.PSVersion.Major -ne 5) -or ($host.Name -notmatch 'Visual Studio Code Host'))
{
[...]
}

gives me a working session.

I'll ping @JanDeDobbeleer about this.

@JanDeDobbeleer
Copy link

@sba923 last time I checked 5 worked, but also on my end that's "best effort". It's legacy 😅

@sba923
Copy link
Author

sba923 commented Nov 1, 2023

@sba923 last time I checked 5 worked, but also on my end that's "best effort". It's legacy 😅

I perfectly. Note that outside of the VScode PowerShell Extension, oh-my-posh works like a charm with Windows PowerShell 5.1.

I don't want to support Windows PowerShell in whatever I'm implementing. I have to use it wherever PowerShell 7.x can't be used. And I thus need to debug those scripts...

@JanDeDobbeleer
Copy link

@sba923 can you get me the content of $error? Pretty sure this is related to not having any console properties defined when in this extension's shell runtime.

@sba923
Copy link
Author

sba923 commented Nov 1, 2023

How do you suggest to capture it? As soon as oh-my-posh loads, the prompt becomes unusable...

@JanDeDobbeleer
Copy link

@ryan-beesley
Copy link

I think there must be more to this. I have oh-my-posh, but only for PowerShell Core 7.3.9. Only $PROFILE.CurrentUserCurrentHost exists and it only has an extension for $env:Path to include some scripts I keep available. These scripts are not loaded at all, only the Path environment variable is modified. The version of PSReadLine I'm using in Windows PowerShell is 2.0.0. I'm set "powershell.enableProfileLoading": false, and it did not resolve my problem.

Version: 1.84.2 (system setup)
Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
Date: 2023-11-09T10:51:52.184Z
Electron: 25.9.2
ElectronBuildId: 24603566
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.22000
PS C:\Users\RyanBeesley> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22000.2538
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22000.2538
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PS C:\Users\RyanBeesley> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpo...
Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSRe...


PS C:\Users\RyanBeesley>

@github-actions github-actions bot added the Stale label Nov 16, 2023
Copy link
Contributor

This issue has been labeled as needing feedback and has not had any activity for one or more weeks. It has been closed for housekeeping purposes.

@sba923
Copy link
Author

sba923 commented Nov 22, 2023

@ryan-beesley are you still able to repro this?

As far as I'm concerned, I've just disabled oh-my-posh when running Windows PowerShell with the VScode extension.

(@JanDeDobbeleer the problem's still present with 18.25.1)

@JanDeDobbeleer
Copy link

JanDeDobbeleer commented Nov 22, 2023

@sba923 this should be fixed here. It fails in this handler: https://github.com/JanDeDobbeleer/oh-my-posh/blob/b31f01a1a3a127a721e4cf0b5afef9c91f462203/src/shell/scripts/omp.ps1#L212 I can extend the try-catch there as well but in my opinion, the behaviour should be identical here as when running native pwsh.

@sba923
Copy link
Author

sba923 commented Nov 22, 2023

@sba923 this should be fixed here. It fails in this handler: https://github.com/JanDeDobbeleer/oh-my-posh/blob/b31f01a1a3a127a721e4cf0b5afef9c91f462203/src/shell/scripts/omp.ps1#L212 I can extend the try-catch there as well but in my opinion, the behaviour should be identical here as when running native pwsh.

I hate to say, but that's clearly not the case:

image

@JanDeDobbeleer
Copy link

I hate to say, but that's clearly not the case:

What do you mean?

@sba923
Copy link
Author

sba923 commented Nov 22, 2023

I hate to say, but that's clearly not the case:

What do you mean?

I mean the issue is still present with oh-my-posh 18.26.1.

What did you mean by "it should be fixed here"?

@JanDeDobbeleer
Copy link

@sba923 this repository.

@sba923
Copy link
Author

sba923 commented Nov 22, 2023

@sba923 this repository.

Oh, I see... need to find out how to get the issue reopened... @SydneyhSmith?

@ryan-beesley
Copy link

@sba923, yes, this is still an issue for me. I resorted to using Windows PowerShell ISE to edit and debug my script for Windows PowerShell 5.1, so while this is a workaround the issue raised by this work item still applies to me and isn't seemingly related to oh-my-posh. I have oh-my-posh installed, but this problem remains even when I have profile loading disabled.

I just went through and updated everything (Oh-My-Posh, PowerShell 7.4.0), again, and restarted VSCode. The extension is now working with Windows PowerShell 5.1, so this has been resolved now for me. Neither update seems as though it should have had an impact, because the 5.1 profile wasn't being loaded, only $PROFILE.CurrentUserCurrentHost exists for both Windows PowerShell 5.1 and PowerShell Core 7.4.0, different scripts, and with regard to Windows PowerShell $PROFILE.CurrentUserCurrentHost only adds a directory to the $env:Path so Oh-My-Posh wasn't being initiated at all. I'm not sure what changed to make it work.

@andyleejordan
Copy link
Member

Sorry, just getting back from vacation. Glad to hear it's working!

@sba923
Copy link
Author

sba923 commented Nov 29, 2023

Sorry, just getting back from vacation. Glad to hear it's working!

I hate to say, but it's not for me...

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash.
Projects
None yet
Development

No branches or pull requests

5 participants