PowerShell / PowerShell/PowerShellEditorServices

Terminal Hangs when attaching to PowerShell 5.1

未关闭
#1,369 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Area-Debugging Issue-Bug
主要语言
C#
星标
767
派生
266
平均合并
3 天 16 小时
30 天内合并 PR
1

描述

We have a feature of the PowerShell Universal extension where we allow you to connect to the PowerShell process running the dashboard script. This works by simply calling Enter-PSHostProcess in the PowerShell Integrated Terminal.

Once connected, you can then use Get-Runspace and Debug-Runspace to attach and debug the runspaces in question. This works well and opens a PS1 file and breaks after a Wait-Debugger call.

What doesn't work is that after we've attached, if you attempt to issue a command in the terminal, it hangs.

image

It doesn't hang when connecting to PowerShell 7. It does hang when connecting to PowerShell 5.1.

I don't know if these are related at all but there are some errors in the log. I reproduced this around 10:30 AM so the last two errors may be relevant.

[Info  - 08:41:35] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: PowerShell runtime version: 7.0.3, edition: Core | 
[Info  - 08:41:35] Microsoft.PowerShell.EditorServices.Handlers.PsesDocumentHighlightHandler: highlight handler loaded | 
[Error - 09:00:58] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Execution of the following command(s) completed with errors:

    invoke-build buildserverdeploy -Configuration debug
    Out-Default

 | 
[Warn  - 09:00:58] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Runtime exception occurred while executing command:

System.Management.Automation.ActionPreferenceStopException: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find path 'C:\src\universal\src\output\runtimes' because it does not exist.
   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.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.PowerShellContextService.<>c__DisplayClass89_0`1.<ExecuteCommandAsync>b__0() in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs:line 778
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContextService.ExecuteCommandAsync[TResult](PSCommand psCommand, StringBuilder errorMessages, ExecutionOptions executionOptions) in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs:line 778
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContextService.ExecuteCommandAsync[TResult](PSCommand psCommand, StringBuilder errorMessages, ExecutionOptions executionOptions) in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs:line 823 | 
[Error - 09:28:43] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Execution of the following command(s) completed with errors:

    invoke-build buildserverdeploy -Configuration debug
    Out-Default

 | 
[Warn  - 09:28:43] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Runtime exception occurred while executing command:

System.Management.Automation.ActionPreferenceStopException: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find path 'C:\src\universal\src\output\runtimes' because it does not exist.
   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.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.PowerShellContextService.<>c__DisplayClass89_0`1.<ExecuteCommandAsync>b__0() in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs:line 778
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContextService.ExecuteCommandAsync[TResult](PSCommand psCommand, StringBuilder errorMessages, ExecutionOptions executionOptions) in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs:line 778
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContextService.ExecuteCommandAsync[TResult](PSCommand psCommand, StringBuilder errorMessages, ExecutionOptions executionOptions) in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs:line 823 | 
[Info  - 09:35:22] Microsoft.PowerShell.EditorServices.Services.AnalysisService: Unable to find PSSA settings file at 'c:\src\universal\PSScriptAnalyzerSettings.psd1'. Loading default rules. | 
[Info  - 09:35:22] Microsoft.PowerShell.EditorServices.Services.AnalysisService: PSScriptAnalyzer settings file not found. Falling back to default rules | 
[Error - 10:34:57] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Execution of the following command(s) completed with errors:

    Microsoft.PowerShell.Core\Get-Command New-PSUDashboard -ErrorAction Ignore

 | 
[Error - 10:35:02] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Execution of the following command(s) completed with errors:

    Microsoft.PowerShell.Core\Get-Command New-PSUDashboard -ErrorAction Ignore

 | 

The VS Code log looks clean.

14/10/2020 08:41:24 [NORMAL] - Visual Studio Code v1.50.0 64-bit
14/10/2020 08:41:24 [NORMAL] - PowerShell Extension v2020.6.0
14/10/2020 08:41:24 [NORMAL] - Operating System: Windows 64-bit
14/10/2020 08:41:24 [NORMAL] - Language server starting --
14/10/2020 08:41:24 [NORMAL] -     PowerShell executable: C:\Program Files\PowerShell\7\pwsh.exe
14/10/2020 08:41:24 [NORMAL] -     PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module 'c:\Users\adamr\.vscode\extensions\ms-vscode.powershell-2020.6.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2020.6.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\adamr\.vscode\extensions\ms-vscode.powershell-2020.6.0\modules' -EnableConsoleRepl -StartupBanner "=====> PowerShell Integrated Console v2020.6.0 <=====
" -LogLevel 'Normal' -LogPath 'c:\Users\adamr\.vscode\extensions\ms-vscode.powershell-2020.6.0\logs\1602686484-0f43eafb-f01a-48c5-9945-888347f8f8b71602686475858\EditorServices.log' -SessionDetailsPath 'c:\Users\adamr\.vscode\extensions\ms-vscode.powershell-2020.6.0\sessions\PSES-VSCode-10732-427343' -FeatureFlags @() 
14/10/2020 08:41:24 [NORMAL] -     PowerShell Editor Services args: Import-Module 'c:\Users\adamr\.vscode\extensions\ms-vscode.powershell-2020.6.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2020.6.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\adamr\.vscode\extensions\ms-vscode.powershell-2020.6.0\modules' -EnableConsoleRepl -StartupBanner "=====> PowerShell Integrated Console v2020.6.0 <=====
" -LogLevel 'Normal' -LogPath 'c:\Users\adamr\.vscode\extensions\ms-vscode.powershell-2020.6.0\logs\1602686484-0f43eafb-f01a-48c5-9945-888347f8f8b71602686475858\EditorServices.log' -SessionDetailsPath 'c:\Users\adamr\.vscode\extensions\ms-vscode.powershell-2020.6.0\sessions\PSES-VSCode-10732-427343' -FeatureFlags @() 
14/10/2020 08:41:24 [NORMAL] - pwsh.exe started.
14/10/2020 08:41:24 [NORMAL] - Waiting for session file
14/10/2020 08:41:33 [NORMAL] - Session file found
14/10/2020 08:41:33 [NORMAL] - Registering terminal close callback
14/10/2020 08:41:33 [NORMAL] - Registering terminal PID log callback
14/10/2020 08:41:33 [NORMAL] - pwsh.exe PID: 23676
14/10/2020 08:41:33 [NORMAL] - Language server started.
14/10/2020 08:41:33 [NORMAL] - {"status":"started","languageServiceTransport":"NamedPipe","languageServicePipeName":"\\\\.\\pipe\\PSES_0qvw0oh4.1xl","debugServiceTransport":"NamedPipe","debugServicePipeName":"\\\\.\\pipe\\PSES_jyeuyt2z.21h"}
14/10/2020 08:41:33 [NORMAL] - Connecting to language service on pipe \\.\pipe\PSES_0qvw0oh4.1xl...
14/10/2020 08:41:33 [NORMAL] - Language service connected.

Let me know if you need any more info.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,使用 Enter-PSHostProcess 针对 PowerShell 5.1 重现卡死,然后检查第 778 行 ExecuteCommandAsync 附近的 PowerShellContextService.cs,以及对 Get-Runspace 和 Debug-Runspace 的处理。完成的标准是:附加后发出的命令在 PowerShell 5.1 上仍能保持响应,同时现有的 PowerShell 7 行为仍然有效。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp, powershell
领域
devtools
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。