PowerShell / PowerShell/PowerShellEditorServices

Terminal Hangs when attaching to PowerShell 5.1

Offen
#1,369 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Area-Debugging Issue-Bug
Vorherrschende Sprache
C#
Sterne
767
Forks
266
Ø Merge
3 T. 16 Std.
Gemergte PRs (30 T.)
1

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, den Hänger mit Enter-PSHostProcess gegen PowerShell 5.1 zu reproduzieren, und untersuche dann PowerShellContextService.cs im Bereich von ExecuteCommandAsync in Zeile 778 sowie die Behandlung von Get-Runspace und Debug-Runspace. Als erledigt gilt die Aufgabe, wenn nach dem Anhängen ausgeführte Befehle unter PowerShell 5.1 weiterhin reagieren und das bestehende Verhalten von PowerShell 7 weiterhin funktioniert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp, powershell
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.