PowerShell / PowerShell/PowerShellEditorServices

Terminal Hangs when attaching to PowerShell 5.1

Aperta
#1,369 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Area-Debugging Issue-Bug
Lingua principale
C#
Stelle
767
Fork
266
Merge medio
3g 16h
PR unite (30g)
1

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il blocco con Enter-PSHostProcess su PowerShell 5.1, quindi esamina PowerShellContextService.cs intorno a ExecuteCommandAsync alla riga 778 e la gestione di Get-Runspace e Debug-Runspace. Il lavoro è completato quando i comandi eseguiti dopo l’aggancio rimangono reattivi su PowerShell 5.1, mentre il comportamento esistente di PowerShell 7 continua a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp, powershell
Ambito
devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.