From d2484af1ba24027dfbdcff4f1d93e6db3d011d6e Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 19 Aug 2021 16:24:17 -0700 Subject: [PATCH 1/2] Fix erroneous cancellation tokens These needed to be explicitly `None` to indicate that they should not be cancelled (for various reasons). --- .../Services/DebugAdapter/Handlers/DisconnectHandler.cs | 4 ++-- .../PowerShellContext/Session/PSReadLinePromptContext.cs | 4 +++- .../Services/Symbols/Vistors/AstOperations.cs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DisconnectHandler.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DisconnectHandler.cs index 9fa9c3e65..4f2b8e85b 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DisconnectHandler.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DisconnectHandler.cs @@ -74,8 +74,8 @@ public async Task Handle(DisconnectArguments request, Cancel _logger.LogInformation("Debug adapter is shutting down..."); #pragma warning disable CS4014 - // Trigger the clean up of the debugger. No need to wait for it. - Task.Run(_psesDebugServer.OnSessionEnded, cancellationToken); + // Trigger the clean up of the debugger. No need to wait for it nor cancel it. + Task.Run(_psesDebugServer.OnSessionEnded, CancellationToken.None); #pragma warning restore CS4014 return new DisconnectResponse(); diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/PSReadLinePromptContext.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/PSReadLinePromptContext.cs index e74519913..62f5e21e2 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/PSReadLinePromptContext.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/PSReadLinePromptContext.cs @@ -144,7 +144,9 @@ public async Task InvokeReadLineAsync(bool isCommandLine, CancellationTo readLineCommand, errorMessages: null, s_psrlExecutionOptions, - cancellationToken).ConfigureAwait(false); + // NOTE: This command should always be allowed to complete, as the command itself + // has a linked cancellation token such that PSReadLine will be correctly cancelled. + CancellationToken.None).ConfigureAwait(false); string line = readLineResults.FirstOrDefault(); diff --git a/src/PowerShellEditorServices/Services/Symbols/Vistors/AstOperations.cs b/src/PowerShellEditorServices/Services/Symbols/Vistors/AstOperations.cs index e9972b12d..2251c56b3 100644 --- a/src/PowerShellEditorServices/Services/Symbols/Vistors/AstOperations.cs +++ b/src/PowerShellEditorServices/Services/Symbols/Vistors/AstOperations.cs @@ -62,7 +62,7 @@ public static async Task GetCompletionsAsync( ILogger logger, CancellationToken cancellationToken) { - if (!s_completionHandle.Wait(0, cancellationToken)) + if (!s_completionHandle.Wait(0, CancellationToken.None)) { return null; } From 2316a2d0bcecb000217db1f5377fde8174385035 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 23 Aug 2021 10:39:03 -0700 Subject: [PATCH 2/2] Revert addition of `shell.Stop()` to `ExecuteCommandAsync()` This unintentionally introduced a bug with the PSReadLine integration which left users needing to press `ENTER` in the console to start or continue the debugger. --- .../Services/PowerShellContext/PowerShellContextService.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs index ff2db32a7..ec3923db0 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs @@ -765,7 +765,6 @@ public async Task> ExecuteCommandAsync( } // This is the primary reason that ExecuteCommandAsync takes a CancellationToken - cancellationToken.Register(() => shell.Stop()); return await Task.Run>( () => shell.Invoke(input: null, invocationSettings), cancellationToken) .ConfigureAwait(false);