Skip to content

Commit 1376621

Browse files
Move context frame pop logic around
This should make default prompt spam significantly less likely or impossible. Also fixes a scenario where if the REPL loop is evaluating and in an attached process, closing the attachee would dead lock.
1 parent c88f7c2 commit 1376621

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

+20-7
Original file line numberDiff line numberDiff line change
@@ -680,18 +680,30 @@ private void RunExecutionLoop(bool isForDebug = false)
680680
}
681681

682682
using CancellationScope cancellationScope = _cancellationContext.EnterScope(false);
683-
DoOneRepl(cancellationScope.CancellationToken);
683+
684+
try
685+
{
686+
DoOneRepl(cancellationScope.CancellationToken);
687+
}
688+
catch (OperationCanceledException)
689+
{
690+
if (isForDebug)
691+
{
692+
while (Runspace is { RunspaceIsRemote: true } remoteRunspace
693+
&& !remoteRunspace.RunspaceStateInfo.IsUsable())
694+
{
695+
PopPowerShell(RunspaceChangeAction.Exit);
696+
}
697+
698+
return;
699+
}
700+
}
684701

685702
while (!ShouldExitExecutionLoop
686703
&& !cancellationScope.CancellationToken.IsCancellationRequested
687704
&& _taskQueue.TryTake(out ISynchronousTask task))
688705
{
689706
task.ExecuteSynchronously(cancellationScope.CancellationToken);
690-
while (Runspace is { RunspaceIsRemote: true } remoteRunspace
691-
&& !remoteRunspace.RunspaceStateInfo.IsUsable())
692-
{
693-
PopPowerShell(RunspaceChangeAction.Exit);
694-
}
695707
}
696708

697709
if (_shouldExit
@@ -759,7 +771,7 @@ private void DoOneRepl(CancellationToken cancellationToken)
759771
}
760772
catch (OperationCanceledException)
761773
{
762-
// Do nothing, since we were just cancelled
774+
throw;
763775
}
764776
// Propagate exceptions thrown from the debugger when quitting.
765777
catch (TerminateException)
@@ -828,6 +840,7 @@ public void WriteWithPrompt(PSCommand command, CancellationToken cancellationTok
828840

829841
private string InvokeReadLine(CancellationToken cancellationToken)
830842
{
843+
cancellationToken.ThrowIfCancellationRequested();
831844
try
832845
{
833846
_readKeyCancellationToken = cancellationToken;

0 commit comments

Comments
 (0)