Skip to content
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

Powershell Extension never starts. Terminal Message: "Starting server, deregistering host logger and registering shutdown listener" #4963

Open
6 tasks done
po4htaeszq opened this issue Apr 5, 2024 · 11 comments
Labels
Area-Engine Issue-Bug A bug to squash.

Comments

@po4htaeszq
Copy link

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

Powershell Extension was working for years and then tab complete stopped working. Tying to figure it out, I noticed that on another server that while the default session was starting up, the tab complete in Code editor didn't work. As soon as the Powershell session/terminal was at a prompt, all tab functions as expected. So on my Wondws 2019 server, I noticed that the terminal never gets to a prompt.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : ConsoleHost
Version          : 7.4.1
InstanceId       : a76ca68b-807a-4ab1-b5a6-aac0b11d35a6
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

1.88.0
5c3e652f63e798a5ac2f31ffd0d863669328dc4c
x64

Extension Version

ms-vscode.?[7mpowershell?[[email protected]

Steps to Reproduce

Run VS Code
Click on a PS1 script to load into the Code editor
Auto detect sees Powershell but never gets the extension started.

While troubleshooting, I tried switching to Win PowerShell x86 and it came up OK. I then reviewed the known issue however I am not running Av3cto. In addition one of the servers where this setup does work, both servers share the same security and monitoring software packages.
Problem server is Windows 2019 build 17763
Working server: Windows 2022 Server build 20348
FYI, my debug logs were not in the path listed in the troubleshooting doc. They were located here:
C:\Users<SamAccountName>\AppData\Roaming\Code\User\globalStorage\ms-vscode.powershell\logs\1712264618-f696d629-7e89-40d6-a0df-133a37127f071712263703182

Visuals

VS Code screen shot
There isn't much to see. The circular arrows lower right on the image spin for as long as VS Code is running. I've had VSCode for running days and the terminal never gets to a prompt.

Logs

The logs were not in the location noted in the article. From the VS Code terminal, the verbose output from debug gave the log path. C:\Users\SATrudeauJ1\AppData\Roaming\Code\User\globalStorage\ms-vscode.powershell\logs

EditorServices.log
StartEditorServices.log
StartEditorServices-temp3D1BB094.log
StartEditorServices-temp3207AE2C.log
StartEditorServices-temp13480F4F.log
vscode-powershell.log

@po4htaeszq po4htaeszq added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Apr 5, 2024
@andyleejordan
Copy link
Member

Can you try disable profile loading with powershell.enableProfileLoading and also try installing the pre-release? Thanks!

@JustinGrote JustinGrote added Needs: Author Feedback Please give us the requested feedback! Area-Engine and removed Needs: Triage Maintainer attention needed! labels Apr 5, 2024
@github-actions github-actions bot added Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Author Feedback Please give us the requested feedback! labels Apr 5, 2024
@po4htaeszq
Copy link
Author

I was unable to resolve the issue with the suggested steps. Same outcome. While looking into the issue, I logged on to the same server with my standard user account (non-admin) and I was able to run VS Code as suggested. While loged in I noticed that the Activity Bar was showing the icon for Extension where my troubled session is not seeing a few icon. For the instance we are troubleshooting I do have access to extensions via the Manage button in Activity Bar. With that in mind, I tried to run VS Code in a de-elevated manner using
runas /trustlevel:0x20000 "C:\Program Files\Microsoft VS Code\Code.exe"

Another thing I wanted to mention:
I noticed the version of VS Code was not the same as the install. It seems I have exes in two paths and I'm guessing this is due to installing via both the System and User installers for VS Code.
C:\Program Files\Microsoft VS Code
C:\Users<SamAccountName>\AppData\Local\Programs\Microsoft VS Code
I tested with both versions configured to not load the Powershell profile and running the latest Pre-Release Powershell extension and the outcome was the same as initially reported - did not work.
The cursor/command prompt never returned to the terminal session. It seems likely that the elevated access of my account may be related to the issue.
ActivityBarComparison

@po4htaeszq
Copy link
Author

Hello, I'm wondering if there is anything else you require from me? What are my next steps? I was using the powershell extension for critical and complicated functions and its at a standstill. How can I help to progress this issue? I've already opened a ticket with Microsft Support and it was routed to a V- and I was sent here as the official support.

@JaspreetSran
Copy link

Hello Team,

Could you please help us with an update regarding this issue. The issue is critical for the user.

Thank you.

@andyleejordan
Copy link
Member

Hi,

The presence of the command explorer icon does not indicate if the extension started or not. It's controlled by powershell.sideBar.CommandExplorerVisibility and was disabled by default starting in v2024.2.0. You can re-enable it if you wish, but it doesn't really do anything we believe to be that useful (it's an old "feature" borrowed from the ISE, and it's on in ISE-mode).

My guess is that the user has the AllSigned policy set, and since Microsoft has changed the certificates being used to sign distributed code (such as our extension) the certificate needs to be trusted again.

@andyleejordan
Copy link
Member

More info in this thread: #3741

@po4htaeszq
Copy link
Author

This is not about command explorer. Out of desperation I was simply describing any possible difference between a working and non-work powershell extension.
To be clear, this problem has been ongoing for a few months, at first I just worked around it but its not doable anymore.
I was asked to test the newer versions of the Powershell extension here for this issue so it can't be the cause of the issue. I checked PSReadline files and they were signed on April 3. So I simply moved back to 2024.0.0 to ensure that we're not introducing some other issue.
I am not seeing invalid cert warnings.
I do not run in allsigned on my development server
I have a lot I could say about #3741 and how it was handles but it's not the issue here.

Back to the issue at hand.
As related to the execution policy Allsigned, let me say it explicitly. I am not restricted with respect to how I set my execution policy. I do prefer RemoteSigned. Before opening this issue and as per "Troubleshooting PowerShell Extension Issues" I reproduced the issue with Powershell extension in VS Code with the following setting and included the logs on initial report of this issue. "powershell.developer.editorServicesLogLevel": "Diagnostic"
In those logs attached with the initial report, there is a log file called "vscode-powershell.log". In that log there are several instance of the startup command and it shows the following:
"4/4/2024 5:03:39 PM [VERBOSE] - Starting process: C:\Program Files\PowerShell\7\pwsh.exe -NoProfile -ExecutionPolicy Bypass"

I don't receive any popup requests or warnings and that includes anything related to running unpublished software.
I don't see any indication that its an execution policy issue. Do you see something in the logs that indicate an execution policy?
If I open an additional Powershell session (core 7.4), a new terminal session opens without issue and in that terminal I can tab complete commands in the module path, etc with no errors. Psreadline feature like bck-i-search work withone issue. Its just the Powershell session that is started by the extension and relied upon for the editor to work properly.
If I logon to the server with a standard user (Remote desktop access, no elevalated local group memberships), Powershell Extension completes loading and tab complete and the rest of the ISE like features of the extension work.
I've been writing scripts and functions on this server while logged in as a local admin for years without issue. If this is a by-design issue, I'd assume the issue would be noted somewhere within the release that instegated the change and would be easy to identify in 'known issues with this version...'. Whatever is causing this issue was not resolved by uninstalling and reverting back all items (VSCode, Powershell core, Powershell extension) back to circa June 2023. I didn't revert 5.1 because there's no separate patch that controls 5.1 as far as I know.
I've taken an image of all GPO results related to Powershell. I can't copy my complete GPO, however I have the gpresult /H report and searched for "Powershell" as seen in the image upper right, there are only three instances of the word powershell and none are related to execution policy.
applied PowerShell GPO

I also ran Get-PsExecutionPolicy directly from Powershell with the following policies.
On 5.1.17763.5696 its Unrestricted
On 7.4.1 its RemoteSigned

Can this be unlinked from #3741? Its not going to be helpful to keep these issues linked.

@andyleejordan
Copy link
Member

Ok, different issue then, good to know!

@andyleejordan
Copy link
Member

If I logon to the server with a standard user (Remote desktop access, no elevalated local group memberships), Powershell Extension completes loading and tab complete and the rest of the ISE like features of the extension work.

Ok so it is working, it's just when you switch to an admin user? The end of your logs show this:

4/4/2024 5:35:25 PM [VERBOSE] - Connecting to language service...
4/4/2024 5:35:25 PM [VERBOSE] - Workspace was undefined, using homedir!
4/4/2024 5:35:25 PM [VERBOSE] - Language service connected.
4/4/2024 6:20:18 PM [WARNING] - PowerShell process terminated or Extension Terminal was closed, PID: 6544

so it looks like it has finished loading and connecting, and is just hung up with your prompt. Have you tried disabling profile loading like I first suggested? (It's on in the logs you provided.) What's the value of your prompt function, are you trying to load third-party modules like oh-my-posh etc.?

@po4htaeszq
Copy link
Author

I feel that we're getting the timing and steps taken out of order and it may be taking us down the wrong path.
You are correct, the logs were collected while I was doing the repro to report the issue. Having a profile is how I use the VS Code with the Powershell extension. I was following the PSE TS doc. That's the date and config I had to open this issue.
Next - On the suggestion of this community and to rule out my loading of modules, I set the start up to not load a profile and ran it with and without the the pre-release of the PSE. I then reported back "I was unable to resolve the issue with the suggested steps." I'm sure those logs are still in the temp folder if we want them. If you still think its adventageous to chat on my profile, No problem, I just don't want to go sideways.
My Next Step
Have another server admin run VS Code with PSE as his elevated account with no profile and debug logging enable and see if he's gets this thing fired up. If he can repro, I'll start restoring servers until I find it works 100%. If I recall, it was working fine in June 2023.
Please, if you want newer set of debug logs. Please let me know exactly what versions and config you are looking for and I'll get it posted ASAP.

@andyleejordan
Copy link
Member

andyleejordan commented Apr 16, 2024

Have another server admin run VS Code with PSE as his elevated account with no profile and debug logging enable and see if he's gets this thing fired up. If he can repro, I'll start restoring servers until I find it works 100%. If I recall, it was working fine in June 2023.

I think that's a good idea. It's hard to say what's happening on your machine when you login as an admin. For what it's worth, when you try reinstalling the extension, make sure you go to ~/.vscode/extensions and delete the extension folder there, in case it's some permissions issue. I don't that that the reinstall button in the marketplace necessarily purges that correctly (given I've found stuff there I'd previously uninstalled). There are also caches in %AppData%\Roaming\Code and our extension's local storage in %AppData%\Roaming\Code\User\globalStorage\ms-vscode.powershell.

@SydneyhSmith SydneyhSmith removed the Needs: Maintainer Attention Maintainer attention needed! label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Engine Issue-Bug A bug to squash.
Projects
None yet
Development

No branches or pull requests

5 participants