Skip to content

Clean up and pop dead runspace when using 'attach' #896

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
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
19 changes: 15 additions & 4 deletions src/PowerShellEditorServices/Session/PowerShellContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ await Task.Factory.StartNew<IEnumerable<TResult>>(
if (!e.SerializedRemoteException.TypeNames[0].EndsWith("PipelineStoppedException"))
{
// Rethrow anything that isn't a PipelineStoppedException
throw e;
throw;
}
}

Expand Down Expand Up @@ -608,7 +608,18 @@ await Task.Factory.StartNew<IEnumerable<TResult>>(
}
finally
{
// Get the new prompt before releasing the runspace handle
// 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 aha!

this.PopRunspace();
}

// Get the new prompt before releasing the runspace:?> handle
if (executionOptions.WriteOutputToHost)
{
SessionDetails sessionDetails = null;
Expand Down Expand Up @@ -792,10 +803,10 @@ public async Task ExecuteScriptWithArgs(string script, string arguments = null,

var strBld = new StringBuilder();

// The script parameter can refer to either a "script path" or a "command name". If it is a
// The script parameter can refer to either a "script path" or a "command name". If it is a
// script path, we can determine that by seeing if the path exists. If so, we always single
// quote that path in case it includes special PowerShell characters like ', &, (, ), [, ] and
// <space>. Any embedded single quotes are escaped.
// <space>. Any embedded single quotes are escaped.
// If the provided path is already quoted, then File.Exists will not find it.
// This keeps us from quoting an already quoted path.
// Related to issue #123.
Expand Down