Remote PSSession disconnects after launch debugging session ends
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 55/100
Línea de trabajo
Comienza en ConfigurationDoneHandler.LaunchScriptAsync y compara su gestión de finalización con OnExecutionCompletedAsync en LaunchAndAttachHandler.cs; después, sigue DisconnectHandler.cs y el bucle de ejecución de PsesInternalHost.cs descrito en el informe. El cambio está completo cuando una sesión de depuración de lanzamiento finalizada normalmente deja activa la PSSession remota para el siguiente comando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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 PowerShell Editor Services itself and does not reproduce in a standalone PowerShell instance, and is not an issue with my editor.
- I have verified that I am using the latest version of PowerShell Editor Services.
- If this is a security issue, I have read the security issue reporting guidance.
Summary
When using remote PowerShell debugging from VS Code server (Linux → Windows over PSSession over SSH) with a launch configuration and path mappings, the remote PSSession unexpectedly drops immediately after the debug session finishes. As soon as any command is run post-debugging, the user gets kicked back to the local session.
Technical Analysis
After investigating the PowerShellEditorServices codebase, I traced the issue through this execution flow:
-
Launch sessions never set
ExecutionCompleted = truewhen they finish normally. Unlike Attach sessions (which set this viaOnExecutionCompletedAsyncinLaunchAndAttachHandler.cs:493), Launch sessions execute viaConfigurationDoneHandler.LaunchScriptAsync()which has no equivalent completion handler. -
When the debug session ends,
DisconnectHandlerchecksExecutionCompleted(DisconnectHandler.cs:55-58) -
Because
ExecutionCompletedis stillfalse, it calls_debugService.Abort() -
Abort()callsSetDebugResuming(DebuggerResumeAction.Stop)(PowerShellDebugContext.cs:97) -
SetDebugResuming()calls_psesHost.SetExit()(PowerShellDebugContext.cs:115) -
SetExit()sets_shouldExit = trueon the remote frame when it's a REPL with multiple frames (PsesInternalHost.cs:360-371) -
The next time the run loop executes (
RunExecutionLoop, around line 917), it sees_shouldExit == truefor a remote, non-nested REPL frame and callsPopPowerShell()(PsesInternalHost.cs:917-922) -
PopPowerShell()pops the remote REPL frame and detects the runspace change, which causes it to pop from_runspaceStack, exiting the PSSession (PsesInternalHost.cs:763-790)
Root Cause
Launch sessions do not set ExecutionCompleted = true when the debugged script finishes. This causes DisconnectHandler to treat a normal completion as an abort scenario, calling Abort() which ultimately sets _shouldExit = true on the remote REPL frame, causing the PSSession to exit.
Proposed Fix
Set ExecutionCompleted = true in ConfigurationDoneHandler.LaunchScriptAsync() after script execution completes:
await _executionService.ExecutePSCommandAsync(
command,
CancellationToken.None,
s_debuggerExecutionOptions).ConfigureAwait(false);
// Fix: Mark execution as completed for launch sessions
if (_debugStateService is not null)
{
_debugStateService.ExecutionCompleted = true;
}
_debugAdapterServer?.SendNotification(EventNames.Terminated);
This aligns the behavior of Launch sessions with Attach sessions, which already set this flag in OnExecutionCompletedAsync.
PowerShell Version
$PSVersionTable
Name Value
---- -----
PSVersion 7.5.4
PSEdition Core
GitCommitId 7.5.4
OS Rocky Linux 8.10 (Green Obsidian)
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Editor Version
emacs --version
GNU Emacs 30.1.90
PowerShell Editor Services Version
$pseditor.EditorServicesVersion
Major Minor Build Revision
----- ----- ----- --------
4 4 0 0
Steps to Reproduce
Steps to Reproduce
Set up VS Code server on Linux
Configure launch debugging with path mappings
Establish remote PSSession to Windows machine over SSH
Set breakpoint
Start a launch-based debug session
Let the debug session complete normally
Run any command in the remote session
Observe that the PSSession drops and returns to local session
Expected Behavior
The remote PSSession should remain active after a launch debug session completes, allowing continued work in the remote context.
Actual Behavior
The remote PSSession drops immediately after the first command is run following debug session completion.
Visuals
No response
Logs
No response
- Lenguaje dominante
- C#
- Estrellas
- 767
- Forks
- 266
- Merge medio
- 3 d 16 h
- PR fusionados (30 d)
- 1
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de PowerShell/PowerShellEditorServices
-
[Bug] None of the string overloads of `EditorExtensionServiceProvider.GetService()` work on .NET. Abierto
PowerShell/PowerShellEditorServices#2331 · 1 reacción · 2 asignados ·
-
Area-Language Server Issue-Enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
PowerShell/PowerShellEditorServices#2315 · 1 comentario ·
-
Area-Debugging Issue-Enhancement
PowerShell/PowerShellEditorServices#2294 · 1 reacción · 2 asignados ·
-
Issue-Bug Needs: Triage
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
PowerShell/PowerShellEditorServices#2293 · 1 comentario ·
-
PowerShell/PowerShellEditorServices#2282 · 1 comentario · 1 reacción · 2 asignados ·
Todos los issues de PowerShell/PowerShellEditorServices
Issues similares
-
Documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
cake-build/cake#5024 ·
-
Gå gjennom ESLint-suppressions AbiertoFrontend status/draft TechnicalDebt
Dificultad 2/5 1-2 días Aptitud para principiantes 75/100
Altinn/altinn-auth#4143 ·
-
.NET Flaky Test Testing Tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
getsentry/sentry-dotnet#5617 · 1 comentario ·
-
Add more to the documentation Abierto:watch: Not Triaged dotnet-fsharp/svc
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
-
Client customer-reported needs-team-attention question Service Attention WebPubSub
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Azure/azure-sdk-for-net#63292 · 3 comentarios · 1 reacción ·