Skip to content

Clean up and pop dead runspace when using 'attach' for V2 #897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public IEnumerable<TResult> ExecuteCommandInDebugger<TResult>(

public void StopCommandInDebugger(PowerShellContext powerShellContext)
{
powerShellContext.CurrentRunspace.Runspace.Debugger.StopProcessCommand();
// If the RunspaceAvailability is None, the runspace is dead and we should not try to run anything in it.
if (powerShellContext.CurrentRunspace.Runspace.RunspaceAvailability != RunspaceAvailability.None)
{
powerShellContext.CurrentRunspace.Runspace.Debugger.StopProcessCommand();
}
}

public void ExitNestedPrompt(PSHost host)
Expand Down
13 changes: 12 additions & 1 deletion src/PowerShellEditorServices/Session/PowerShellContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -765,10 +765,21 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
executionOptions,
true);

throw e;
throw;
}
finally
{
// If the RunspaceAvailability is None, it means that the runspace we're in is dead.
// If this is the case, we should abort the execution which will clean up the runspace
// (and clean up the debugger) and then pop it off the stack.
// An example of when this happens is when the "attach" debug config is used and the
// process you're attached to dies randomly.
if (this.CurrentRunspace.Runspace.RunspaceAvailability == RunspaceAvailability.None)
{
this.AbortExecution(shouldAbortDebugSession: true);
this.PopRunspace();
}

// Get the new prompt before releasing the runspace handle
if (executionOptions.WriteOutputToHost)
{
Expand Down