Skip to content
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

Debugger won't run until ENTER is pressed in integrated console #3513

Closed
4 tasks done
andyleejordan opened this issue Aug 19, 2021 · 8 comments · Fixed by PowerShell/PowerShellEditorServices#1555
Closed
4 tasks done
Assignees
Labels

Comments

@andyleejordan
Copy link
Member

andyleejordan commented Aug 19, 2021

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

This is currently only happening with v2021.8.1-preview (the PowerShell Preview extension) and PowerShell 7, but it happens on Windows and macOS. @SeeminglyScience confirmed for me: run any PowerShell script in the debugger, it won't actually do anything (like run to a breakpoint or completion) until you manually go to the integrated console and press ENTER.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.59.1
3866c3553be8b268c8a7f8c0482c0c0177aa8bfa
x64

Extension Version

ms-vscode.powershell-preview@2021.8.1

Steps to Reproduce

  1. Run PowerShell script in debugger
  2. It hangs until ENTER is sent

Visuals

No response

Logs

No response

@andyleejordan andyleejordan added Issue-Bug A bug to squash. Area-Debugging Bug: PowerShell Core Bugs when using PowerShell Core. labels Aug 19, 2021
@andyleejordan andyleejordan added this to the Committed-vNext milestone Aug 19, 2021
@andyleejordan andyleejordan self-assigned this Aug 19, 2021
@andyleejordan andyleejordan moved this from To do to In progress in Debug/Terminal Reliability Aug 19, 2021
@andyleejordan
Copy link
Member Author

Before ENTER is pressed the logs are:

[Trace - 4:10:56 PM] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Attempting to execute command(s):     c:\\Users\\andschwa\\src\\vscode-powershell\\examples\\ContentViewTest.ps1\r\n | "
}


Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Attempting to execute command(s):     c:\Users\andschwa\src\vscode-powershell\examples\ContentViewTest.ps1
 | 
[Trace - 4:10:56 PM] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Sending executionStatusChanged notification | "
}


Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Sending executionStatusChanged notification | 
[Trace - 4:10:56 PM] Received notification 'powerShell/executionStatusChanged'.
Params: {
    "executionOptions": {
        "writeOutputToHost": true,
        "writeErrorsToHost": true,
        "addToHistory": true,
        "interruptCommandPrompt": false,
        "writeInputToHost": true,
        "inputString": null,
        "useNewScope": false
    },
    "executionStatus": 1,
    "hadErrors": false
}

@andyleejordan
Copy link
Member Author

And then afterwards:

[Trace - 4:12:48 PM] Received notification 'window/logMessage'.
Params: {
    "type": 1,
    "message": "Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Execution of the following command(s) completed with errors:\r\n\r\n    __Invoke-ReadLineForEditorServices -CancellationToken System.Threading.CancellationToken\r\n\r\n | "
}


[Error - 4:12:48 PM] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Execution of the following command(s) completed with errors:

    __Invoke-ReadLineForEditorServices -CancellationToken System.Threading.CancellationToken

 | 
[Trace - 4:12:48 PM] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Passing to PowerShell | "
}


Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Passing to PowerShell | 
[Trace - 4:12:48 PM] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Sending executionStatusChanged notification | "
}


Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Sending executionStatusChanged notification | 
[Trace - 4:12:48 PM] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Session state changed --\r\n\r\n    Old state: Ready\r\n    New state: Running\r\n    Result: NotFinished | "
}


Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Session state changed --

    Old state: Ready
    New state: Running
    Result: NotFinished | 
[Trace - 4:12:48 PM] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Debugger stopped execution. | "
}


Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Debugger stopped execution. |

@andyleejordan andyleejordan pinned this issue Aug 19, 2021
@JustinGrote
Copy link
Collaborator

I was bit by this in the pester test adapter, glad to see it's a known issue.

@SeeminglyScience
Copy link
Collaborator

@andschwa I think it's this:

https://github.com/PowerShell/PowerShellEditorServices/blob/6a19daf5bc3e8547fbdc10f351ac2a81d76f9cec/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs#L768

        public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
            PSCommand psCommand,
            StringBuilder errorMessages,
            ExecutionOptions executionOptions,
            CancellationToken cancellationToken = default)
        {
            // (...)
            cancellationToken.Register(() => shell.Stop());

Linked cancellation token sources work by essentially registering a cancellation handler on the target token. I'm guessing the handlers are invoked sequentially on the same thread, and if that's the case then the link handler will never fire because shell.Stop won't finish. The pipeline won't stop until ReadLine returns, and ReadLine won't return until the next cancel handler fires.

Might get away with just changing it to shell.BeginStop()

@andyleejordan
Copy link
Member Author

Haha, oops, our bad. @rjmholt and I added the Stop() registration at the last minute. That explains why this was only in 2.4.8 and not 2.4.7.

@andyleejordan
Copy link
Member Author

This also applies to "Run selection" etc.

@rjmholt
Copy link
Collaborator

rjmholt commented Aug 23, 2021

Oh whoops!

@andyleejordan andyleejordan removed Needs: Maintainer Attention Maintainer attention needed! Bug: PowerShell Core Bugs when using PowerShell Core. labels Aug 23, 2021
Debug/Terminal Reliability automation moved this from In progress to Done Aug 23, 2021
@andyleejordan andyleejordan unpinned this issue Aug 23, 2021
@andyleejordan andyleejordan mentioned this issue Aug 24, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
4 participants