Skip to content

F5 / Ctrl+F5 stops working while Run Active file in Active Terminal with Shift+CTRL+P works #1634

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

Closed
PrzemyslawKlys opened this issue Dec 6, 2018 · 52 comments · Fixed by PowerShell/PowerShellEditorServices#807
Labels

Comments

@PrzemyslawKlys
Copy link
Contributor

Issue Description

Since some time now I often end up with F5, CTRL+F5 being unresponsive. It can happen right after VSCode start, after 1st run, after multiple runs. Totally random. In this case, I was able to run the code once, and subsequent F5 wouldn't work. I can execute a script with SHIFT+CTRL+P and choosing Run active file in active terminal although I am not sure it's the same thing.

Expected Behaviour

Shouldn't bug out.

Actual Behaviour

debuggingstopsworking

Attached Logs

Don't have logs for now, but I can try to get it. From earlier look at logs simply nothing happens when I press F5 or CTRL+F5. It's like those commands get detached or something.

@dhoffman98
Copy link

Rather than creating a new issue, and potentially having it be a duplicate of this one, I am adding a comment.

I also noticed this, but only after the recent upgrade to 1.10.0.

To reproduce... at least on my workstation...
After upgrade to 1.10.0,
Open a script.
Press F5.
Script executes and upon completion, exits debugging mode.

Even if making no changes, press F5 again, and it hangs.
When it hangs, if on the debug view, at the top left of the screen, under the Configuration selector, a tiny blue bar runs across that part of the screen, and never stops. (Under normal circumstances, the bar is still there, but only briefly.)

To workaround, I have had to quit VS Code and open it again.

I tested by downgrading to 1.9, and could not reproduce the problem.
Upgrade again to 1.10, and the problem happens again, every time.

@Tuttu
Copy link

Tuttu commented Dec 6, 2018

I support @dhoffman98 report. Yesterday, I was using version 1.9 of the module. Today, I have received the updated 1.10.0 version and now, I can't hit F5 to get my code running. I will only run the first time and then hang on.

As stated by @PrzemyslawKlys , using the "Run Active File in Active Terminal" solution works as a workaround.

@rjmholt rjmholt added Issue-Bug A bug to squash. Area-Debugging labels Dec 6, 2018
@ili101
Copy link

ili101 commented Dec 6, 2018

To downgrade to 1.9.0:

  1. Download https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ms-vscode/vsextensions/powershell/1.9.0/vspackage
  2. settings > "extensions.autoUpdate" : false
  3. open the extensions sidebar, click on the ellipsis in the right upper corner, choose Install from VSIX.

@theRAAPster
Copy link

Same results as @dhoffman98 and @Tuttu. Was fine with the previous version, but started seeing this issue with version 1.10.0 where I only get one shot to run debugging. I did find that using the trash can to kill the Powershell Integrated Console would cause the extension to realize it terminated and it would ask to restart the console, which would allow another run of debugging. Adding some more info:

From EditorServices.log:

2018-12-06 10:48:12.832 [WARNING] tid:20 in 'DispatchMessage' C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageDispatcher.cs: line 147
MessageDispatcher: No handler registered for Event type '$/setTraceNotification'

Code version:

1.29.1
bc24f98b5f70467bc689abf41cc5550ca637088e
x64

Extensions:

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

Editor Services Version:

Major Minor Build Revision
----- ----- ----- --------
1 10 0 0

PSVersionTable:

Name Value
---- -----
PSVersion 5.1.16299.785
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16299.785
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

@PrzemyslawKlys
Copy link
Contributor Author

To be honest I had this issue for at least a couple of weeks/months now. It used to be less common, now it's more common but I had this issue with 1.9.0 as well.

@TylerLeonhardt
Copy link
Member

Thanks for the info! Can everyone attach the logs here so we can get a better idea of what's going on?

@PrzemyslawKlys
Copy link
Contributor Author

1544116548-7ebc2a51-5bb2-4c3d-b5d2-694e610231711544086879684.zip

Hrms... indeed I can restart PowerShell session, run F5 once, and the subsequent session doesn't work.

@theRAAPster
Copy link

@TylerLeonhardt
Copy link
Member

Thanks! It looks like I can repro this too. Let me investigate

@Tuttu
Copy link

Tuttu commented Dec 6, 2018

Do you need more logs @TylerLeonhardt ?

@SydneyhSmith
Copy link
Collaborator

@Tuttu We can always use more logs, thank you!

@viloun
Copy link

viloun commented Dec 6, 2018

I had issues with 1.10 and also 1.9. I actually went all the way back to 1.8.3 and it works. I'm going to leave it at 1.8.3 until the latest version gets fixed. My vscode is at 1.29.1

@maxmonterumisi
Copy link

The same things, with ver. 1.10.0
F5 work only one time.
Only with restart current session I can debug again.
The usual Christmas gift from Microsoft.....

@ronbok
Copy link

ronbok commented Dec 7, 2018

Adding to this as well. This behavior surfaced yesterday w/Ctrl+F5 or F5 w1.10.0. You only get to run a .ps1 once and then I have to do a Reload Window to run another. Painful.

@PrzemyslawKlys
Copy link
Contributor Author

I actually rebinded my keys. I have removed f6 from Pause and added F6 as run active file in active terminal. This works as workaround for now.

@randygrolemund
Copy link

Thanks for the info, fellas, I was having this issue too and thought it was just me. :)

@PrzemyslawKlys
Copy link
Contributor Author

I do hope for a permanent fix. It was driving me crazy for the last few months. Now that it happens all the time I hope it's easier to find the root cause.

@TylerLeonhardt
Copy link
Member

Still investigating this issue. Can some one try something for me:

uninstall, reload, reinstall, reload

the PowerShell extension from the extension marketplace

@ronbok
Copy link

ronbok commented Dec 7, 2018

I think many of us probably already tried that without success. Same issue exists on macOS as well.

@TylerLeonhardt
Copy link
Member

ah... interesting. Just discovered this only happens when the script completes - not when you hit the stop button and try again.

@PrzemyslawKlys
Copy link
Contributor Author

I tried it now. Doesn't work.

@TylerLeonhardt
Copy link
Member

I've found the commit with an issue that I think will fix most people's debugging troubles. @PrzemyslawKlys you might be seeing something else in disguise.

@PrzemyslawKlys
Copy link
Contributor Author

@TylerLeonhardt Nooooo :-( I counted so much this will fix my problem globally. I managed to find another problem (reported) while using workaround for this :/

@TylerLeonhardt
Copy link
Member

@PrzemyslawKlys thank you for opening issues :) it really does help.

@TylerLeonhardt
Copy link
Member

Ok I have a fix for this: PowerShell/PowerShellEditorServices#807

I'm going to try to do a release today. 1.10.1

@PrzemyslawKlys
Copy link
Contributor Author

@TylerLeonhardt for me this works, for a period of time. Now stopped again. I run code as below

Import-Module pswriteword -Force
$FilePath = "$Env:USERPROFILE\Desktop\test111.docx"

$WordDocument = New-WordDocument $FilePath
$Table1 = new-WordTable -WordDocument $WordDocument -NrRows 3 -NrColumns 3
Set-WordTable -Table $Table1 -Design MediumGrid3Accent1 -Supress $true
Add-WordTableCellValue -Table $Table1 -Row 0 -Column 0 -Value "test1" -Supress $true
#Add-WordTableCellValue -Table $Table1 -Row 0 -Column 1 -Value "test2" -Supress $true
#Add-WordTableCellValue -Table $Table1 -Row 0 -Column 1 -Value "test3" -Supress $true
#Add-WordTableCellValue -Table $Table1 -Row 0 -Column 2 -Value "test4" -Supress $true
$Table1.Rows[0].Cells[0]
Set-WordTableRowMergeCells -Table $Table1 -RowNr 0 -ColumnNrStart 0 -ColumnNrEnd 2 -Verbose -Supress $True -TextMerge
$Table1.Rows[0].Cells[0]
Save-WordDocument -WordDocument $WordDocument -OpenDocument -Supress $true

#Set-WordTableRowMergeCells line 101 work with:
#for ($paragraph = 1; $paragraph -lt $Table.Rows[$RowNr].Cells[$ColumnNrStart].Paragraphs.Count; $paragraph++) {

I run it a dozen or more times, changing things inside module PSWriteWord. After some rerun, it just stops working. It's not complicated. I run this, comment some code, rerun it again. I've been hitting this error for months now. There's nothing fancy about that code. It's very simple. If this can be looked at I would appreciate it. The fix you did works, but in the end it still fails.

@SeeminglyScience
Copy link
Collaborator

@PrzemyslawKlys Is it specifically while debugging that module?

I haven't used it myself, but I'm guessing that the module is internally calling either a .NET library or a com object. If that's the case, is it possible that in the scenarios that the debugger stops working, there is something blocking the thread?

For example, do you see the same issue if you try to debug a script that just contains this line:

[System.Threading.Thread]::Sleep([int]::MaxValue)

@PrzemyslawKlys
Copy link
Contributor Author

This module is working with NET library. I don't use COM-Objects. I've seen this happen multiple times on different occasions but it's hard to track because it's totally random. It can work 50 times and 51 stop working, it can stop working on 1st try, 20, and so on. Except for this case that we had with 1.10 it's not easy to pinpoint.

But I've seen this happen on non-net modules (but to be honest it very well could be related to NET - since I could be using some calls to .NET not even thinking about it).

It can be as simple as:

[datetime]::Now()

And I do use it from time to time. Checking for IsNullOrWhiteSpace and so on.

But be aware that I have changed a key binding

image

I use F5 which for me is without debugging and I still hit this.

@PrzemyslawKlys
Copy link
Contributor Author

@SeeminglyScience is there a way I can help debug this?

I just had this situation but in a bit different scenario. By default, I don't use breakpoints. But now I was testing something and I did CTRL+F5 (as per my setup Start Debugging) and it shows something like this:

Hit Line breakpoint on 'C:\Support\GitHub\PSWinReporting\Examples\RunMe-SearchEvents.ps1:5'

[DBG]: PS C:\Support\GitHub\PSWinReporting\Examples> c:\Support\GitHub\PSWinReporting\Private\Events\Get-EventsTranslation.ps1
[DBG]: PS C:\Support\GitHub\PSWinReporting\Examples>

And if you try to press F5 it doesn't do anything. Maybe it's going into that state in Start Without Debugging for some reason?

@SeeminglyScience
Copy link
Collaborator

SeeminglyScience commented Dec 10, 2018

@PrzemyslawKlys The majority of .NET APIs (including [datetime]::Now and [string]::IsNullOrEmpty()) won't (noticeably) block, so it's probably a threading related issue on our end. I've ran into it a few times myself, but there's a few different causes. They are really tricky to debug without running a full debug build day to day and attaching the examine the call stack. I've fixed a few as part of the PSRL changes in 2.0, but there's definitely a few left.

That said, if you'd like to test if it is a .NET API that is blocking, you can run this script from standalone PowerShell console:

$psesProcesses = Get-PSHostProcessInfo |
    Where-Object MainWindowTitle -EQ '' |
    Where-Object ProcessName -In powershell, pwsh

if (-not $psesProcesses) {
    throw 'Cannot find any PSES processes.'
}

foreach ($psesProcess in $psesProcesses) {
    if ($psesProcess.ProcessId -eq $PID) {
        continue
    }
    
    $connectionInfo = [System.Management.Automation.Runspaces.NamedPipeConnectionInfo]::new(
        $psesProcess.ProcessId)
    $rs = $null
    $ps = $null
    try {
        $rs = [runspacefactory]::CreateRunspace($host, $connectionInfo)
        $rs.Open()
        $ps = [powershell]::Create()
        $ps.Runspace = $rs
        $null = $ps.AddScript{
            $rs = Get-Runspace 2
            $pipeline = $rs.GetType().
                GetMethod(
                    'GetCurrentlyRunningPipeline',
                    [System.Reflection.BindingFlags]'Instance, NonPublic').
                Invoke($rs, @())
    
            return $pipeline.Commands |
                Select-Object -First 1 -ExpandProperty CommandText
        }

        return [PSCustomObject]@{
            Id = $psesProcess.ProcessId
            CurrentlyRunningCommand = $ps.Invoke()
        }
    } finally {
        if ($null -ne $ps) {
            $ps.Dispose()
        }
    
        if ($null -ne $rs) {
            $rs.Dispose()
        }
    }
}

That will tell you what the currently executing command is (if any) for each instance of the language server.

@PrzemyslawKlys
Copy link
Contributor Author

I assume I should use this when I hit a problem? And possibly report back with information from it?

@SeeminglyScience
Copy link
Collaborator

@PrzemyslawKlys if CurrentlyRunningCommand is not blank, then there is a high chance something in your script is blocking. If it's part of an actual debug session it could still be us, but if it's "run without debugging" then it's almost definitely something blocking in the script. If that's the case then we can't unblock it, that's a limitation (or more likely a design choice) of the CLR (.NET runtime).

If you run into the issue and CurrentlyRunningCommand is blank, then it's almost definitely PSES.

@PrzemyslawKlys
Copy link
Contributor Author

@SeeminglyScience Ok, will update when I hit the problem again. Thank you.

@rjmholt
Copy link
Contributor

rjmholt commented Dec 10, 2018

I'm going to reopen this issue since it's where most of the information and discussion is and the problem, while better, still exists.

@PrzemyslawKlys
Copy link
Contributor Author

I guess it's PSES :-(

PS C:\Support\GitHub\PSWriteHTML> c:\Support\GitHub\PSWriteHTML\Ignore\PSES-ErrorException.ps1

   Id CurrentlyRunningCommand
   -- -----------------------
26268 {...

@SeeminglyScience
Copy link
Collaborator

@PrzemyslawKlys Can you do (& c:\Support\GitHub\PSWriteHTML\Ignore\PSES-ErrorException.ps1).CurrentlyRunningCommand? Need to see what's running and it got cut off by formatting

@PrzemyslawKlys
Copy link
Contributor Author

Next time ;-) Didn't expect you to respond so fast ;)

@PrzemyslawKlys
Copy link
Contributor Author

Just to make sure I understand this. I should run this command with a path to file that has the code you gave me? I've created (c:\Support\GitHub\PSWriteHTML\Ignore\PSES-ErrorException.ps1) and it holds the code from above so next time I will run this code and then follow it up with the command you just gave me. Right?

@SeeminglyScience
Copy link
Collaborator

Yeah, basically I want to see the expanded value of CurrentlyRunningCommand.

@PrzemyslawKlys
Copy link
Contributor Author

PS C:\Support\GitHub\PSWriteHTML> c:\Support\GitHub\PSWriteHTML\Ignore\PSES-ErrorException.ps1

   Id CurrentlyRunningCommand
   -- -----------------------
26268 {}


PS C:\Support\GitHub\PSWriteHTML> c:\Support\GitHub\PSWriteHTML\Ignore\PSES-ErrorException.ps1

   Id CurrentlyRunningCommand
   -- -----------------------
15996 {...


PS C:\Support\GitHub\PSWriteHTML> c:\Support\GitHub\PSWriteHTML\Ignore\PSES-ErrorException.ps1

   Id CurrentlyRunningCommand
   -- -----------------------
26424 {}


PS C:\Support\GitHub\PSWriteHTML> c:\Support\GitHub\PSWriteHTML\Ignore\PSES-ErrorException.ps1

   Id CurrentlyRunningCommand
   -- -----------------------
26268 {}

Doesn't seem like much help. I do have logs if you need them

@PrzemyslawKlys
Copy link
Contributor Author

@SeeminglyScience
Copy link
Collaborator

Yeah I need the expanded value. Like this:

$originalObject = & c:\Support\GitHub\PSWriteHTML\Ignore\PSES-ErrorException.ps1
$originalObject.CurrentlyRunningCommand

@PrzemyslawKlys
Copy link
Contributor Author

PrzemyslawKlys commented Jan 12, 2019

I was running this:

function Add-Image {
    param(
        [string] $Source,
        [Uri] $UrlLink = '',
        [string] $AlternativeText = '',
        [string] $Class = 'Logo',
        [nullable[int]] $Width,
        [nullable[int]] $Height
    )

    $HTML = Get-Content "$PSScriptRoot\..\Resources\HTML\Image.html"
    if ($UrlLink -eq '') {
        $HTML = $HTML.Replace('target="_blank"', '')
    }
    $HTML = $HTML -Replace 'DefaultHref', $UrlLink `
        -Replace 'DefaultSource', $Source `
        -Replace 'DefaultAlternativeText', $AlternativeText `
        -Replace 'DefaultClass', $Class `
        -Replace 'DefaultWidth', $Width `
        -Replace 'DefaultHeight', $Height
    return $HTML
}


Add-Image 

I tried executing it multiple times 1 by 1 - it worked for like 2 tries and 3rd failed. I quickly checked the output of your command;


PS C:\Support\GitHub\PSWriteHTML> c:\Support\GitHub\PSWriteHTML\Ignore\PSES-ErrorCheck.ps1

            $rs = Get-Runspace 2
            $pipeline = $rs.GetType().
                GetMethod(
                    'GetCurrentlyRunningPipeline',
                    [System.Reflection.BindingFlags]'Instance, NonPublic').
                Invoke($rs, @())

            return $pipeline.Commands |
                Select-Object -First 1 -ExpandProperty CommandText

PS C:\Support\GitHub\PSWriteHTML>

Hope this helps. One thing I noticed is that it's more prone to happen after I leave VSCode open and up and running, doing nothing. However not always.

@PrzemyslawKlys
Copy link
Contributor Author

Run at it again in different module:

PS C:\Support\GitHub\PSSharedGoods\Ignore> c:\Support\GitHub\PSWriteHTML\Ignore\PSES-ErrorCheck.ps1

            $rs = Get-Runspace 2
            $pipeline = $rs.GetType().
                GetMethod(
                    'GetCurrentlyRunningPipeline',
                    [System.Reflection.BindingFlags]'Instance, NonPublic').
                Invoke($rs, @())

            return $pipeline.Commands |
                Select-Object -First 1 -ExpandProperty CommandText

So same output.

@SeeminglyScience
Copy link
Collaborator

@PrzemyslawKlys Wait are you running that in the integrated console itself? That script was intended to run from a separate process that has entered the PSIC process via Enter-PSHostProcess.

If you're able to run that in the integrated console, then it's not hung in the same sense that I was expecting. It sounds like VSCode is either not sending the launch request anymore or PSES just isn't listening.

@PrzemyslawKlys
Copy link
Contributor Author

I'm using the F6 command (I mapped it myself) to execute a file 'Run active file in Active Terminal`

image

And that works fine when F5/CTRL+F5 is broken. So I can type commands in the console manually I can run file by using as above but I can no longer run scripts properly.

@PrzemyslawKlys
Copy link
Contributor Author

And the output I pasted is what you get when you run the script with F6 you gave me after F5 stops working.

@SydneyhSmith SydneyhSmith added this to the 2.0.0 milestone Jan 28, 2019
@SydneyhSmith
Copy link
Collaborator

@PrzemyslawKlys are you still seeing this?

@rjmholt
Copy link
Contributor

rjmholt commented Mar 6, 2020

Possibly this was the same as #2488?

@SydneyhSmith SydneyhSmith removed this from the 2.0.0 milestone Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.