Skip to content

Commit b82d907

Browse files
committed
Fix hang when debug adapter finishes executing
This change fixes a hang that was caused by the recent refactoring of host process server implementations. In the debug adapter implementation, the PowerShellContext was not being disposed at shutdown which was causing the process to stay open because the associated threads were still alive. This change adds the necessary ProtocolServer.Shutdown implementation.
1 parent ae3ad45 commit b82d907

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ protected override void Initialize()
5656
this.SetRequestHandler(EvaluateRequest.Type, this.HandleEvaluateRequest);
5757
}
5858

59+
protected override void Shutdown()
60+
{
61+
Logger.Write(LogLevel.Normal, "Debug adapter is shutting down...");
62+
63+
if (this.editorSession != null)
64+
{
65+
this.editorSession.Dispose();
66+
this.editorSession = null;
67+
}
68+
}
69+
5970
#region Built-in Message Handlers
6071

6172
protected async Task HandleLaunchRequest(

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ protected override void Shutdown()
7070
{
7171
Logger.Write(LogLevel.Normal, "Language service is shutting down...");
7272

73-
this.editorSession.Dispose();
73+
if (this.editorSession != null)
74+
{
75+
this.editorSession.Dispose();
76+
this.editorSession = null;
77+
}
7478
}
7579

7680
#region Built-in Message Handlers

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ void debugService_BreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
6161

6262
void debugService_DebuggerStopped(object sender, DebuggerStopEventArgs e)
6363
{
64-
this.runnerContext.Post(
65-
(o) =>
66-
{
67-
this.debuggerStoppedQueue.Enqueue(e);
68-
}, null);
64+
this.debuggerStoppedQueue.Enqueue(e);
6965
}
7066

7167
public void Dispose()
@@ -119,7 +115,6 @@ await this.debugService.SetBreakpoints(
119115
this.debugService.Continue();
120116

121117
await this.AssertDebuggerStopped(this.debugScriptFile.FilePath, 9);
122-
this.debugService.Continue();
123118

124119
// Abort script execution early and wait for completion
125120
this.debugService.Abort();

0 commit comments

Comments
 (0)