Skip to content

Crashed on script start #1433

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 Jul 12, 2018 · 12 comments · Fixed by #1436
Closed

Crashed on script start #1433

PrzemyslawKlys opened this issue Jul 12, 2018 · 12 comments · Fixed by #1436

Comments

@PrzemyslawKlys
Copy link
Contributor

System Details

  • Operating system name and version: Windows 10 Insiders
  • VS Code version: 1.25
  • PowerShell extension version: 1.81
  • Output from $PSVersionTable:
Copy / paste the following commands into the PowerShell Integrated Console, and paste the output here:

1.25.0
0f080e5267e829de46638128001aeb7ca2d6d50e
x64
PS C:\Users\pklys\OneDrive - Evotec\Support\GitHub\PSTeams> $pseditor.EditorServicesVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      8      1      0


PS C:\Users\pklys\OneDrive - Evotec\Support\GitHub\PSTeams> code --list-extensions --show-versions
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
PS C:\Users\pklys\OneDrive - Evotec\Support\GitHub\PSTeams> $PSVersionTable

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

Issue Description

I am experiencing a problem with... crashing of PowerShell Extension. Copied script from internet. Pasted. Saved. Crashed.

Attached Logs

EditorServices.zip

@nathan-alden-hp
Copy link

I am noticing massive problems with this update. Yesterday I was using 1.8.0 with absolutely no issues. Today, VS Code installed 1.8.1 automatically and I've had nothing but problems. Long terminal start times, long debugging times, frequent crashes... at one point I tried logging out of Windows thinking there was a process hanging somewhere.

The slowdowns and crashes happen even with the simplest of scripts.

@rjmholt
Copy link
Contributor

rjmholt commented Jul 12, 2018

Hi @nathan-alden-hp, would you be able to provide more information about your environment?

The following would be helpful in diagnosing the problem:

  • The output of the following commands from the integrated console:
    • $PSVersionTable
    • code -v
    • code --list-extensions --show-versions
  • Your operating system name/version
  • Your extension logs

@nathan-alden-hp
Copy link

nathan-alden-hp commented Jul 12, 2018

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17134.112
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.112
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
PS > code -v
1.25.1
1dfc5e557209371715f655691b1235b6b26a06be
x64
PS > code --list-extensions --show-versions
[email protected]
[email protected]

OS: Windows 10 Enterprise 1803

I can't get you extension logs at the moment.

VS Code was upgraded to the version I just posted after I submitted my original comment. It seems more stable now, so I'll keep an eye on it.

@rjmholt
Copy link
Contributor

rjmholt commented Jul 12, 2018

Okie doke, no worries. That sounds positive, but please do open an issue if you have any problems. And thanks for uploading that info too!

@rkeithhill
Copy link
Contributor

@PrzemyslawKlys the logs you attached indicate the extension is failing right after a debug session has been started. This is happening within 4 secs of the extension starting up PSES. What exactly are you repro steps? I see you listed:

Copied script from internet. Pasted. Saved. Crashed.

But I'm not sure how any of that would initiate a debug session.

@PrzemyslawKlys
Copy link
Contributor Author

@rkeithhill I may have pressed F5... however keep in mind that I've switched F5 with CTRL+F5 just for this reason. And even thou I don't use debugging at all. I am constantly getting VSCode hanging with that debugging in place. I am not sure where is it coming from.

image

I get VSCode to hang quite often for no reason.

@rkeithhill
Copy link
Contributor

rkeithhill commented Jul 14, 2018

@PrzemyslawKlys Thanks. With that, I can reproduce this. The twist is that you are attempting to "run" the script before the PS editor (and debug) services (PSES) has fully initialized. To avoid this for now, wait until this message in the status bar:

image

changes to:

image

... before attempting to start or debug a script.

Initialization can take ~5-10 seconds for the PSES to fully initialize. In the meantime, we'll be looking for ways to prevent run/launch from VSCode until PSES is initialized.

@PrzemyslawKlys
Copy link
Contributor Author

Great! I guess I am just impatient. Maybe I don’t know how to properly debug scripts in powershell and i essentially press f5 get errors/output, fix things, rerun and so on.

@rkeithhill
Copy link
Contributor

@tylerl0706 @rjmholt Debugged this to this line:

        public Task SendEvent<TParams, TRegistrationOptions>(
            NotificationType<TParams, TRegistrationOptions> eventType,
            TParams eventParams)
        {
            // Some requests may still be in the SynchronizationContext queue
            // after the server stops so don't act on those requests because
            // the protocol channel will already be disposed
            if (this.currentState == ProtocolEndpointState.Shutdown)
            {
                return Task.FromResult(true);
            }

            // Some events could be raised from a different thread.
            // To ensure that messages are written serially, dispatch
            // dispatch the SendEvent call to the message loop thread.

            if (!this.InMessageLoopThread)
            {
                TaskCompletionSource<bool> writeTask = new TaskCompletionSource<bool>();

                this.SynchronizationContext.Post( <<<<===== SynchronizationContext is null at this point
                    async (obj) =>
                    {
                        await this.protocolChannel.MessageWriter.WriteEvent(
                            eventType,
                            eventParams);

                        writeTask.SetResult(true);
                    }, null);

                return writeTask.Task;
            }

This is happening because VSCode, seeing that the extension has been activated, allows run/debug session to be started before PSES is fully initialized.

@rkeithhill
Copy link
Contributor

rkeithhill commented Jul 15, 2018

I have one attempt fix in the extension where we pop a warning dialog if the user attempts to debug/run a script before PSES has finished initializing. The result is this warning notification:
image
Which expands to:
image

edit: s/starting up/starting/

The one downside to this approach is that VSCode opens launch.json in the active editor when we "abort" the call to resolveDebugConfiguration. I have added some comments to a VSCode issue related to this unfortunate side-effect: microsoft/vscode#54213

Ideally, we could either indicate to VSCode that our debugger isn't ready yet OR during the resolveDebugConfiguration call wait 10 secs or so for PSES to finish initializing. But my JS fu isn't quite strong enough to make that work. :-(

rkeithhill added a commit that referenced this issue Jul 15, 2018
Fix #1433

One minor issue is that if you abort (return null|undefined) from
resolveDebugConfiguration, VSCode "helpfully" opens your launch.json
file for you.  Actually, that is quite annoying. I found an issue and on
this and voted it up - microsoft/vscode#54213

Also fix logic for "attach" error.  We only need to test if
OS != Windows.  If on Windows, PS Core supports attach. And tweaked the
error message wording to make more clear.

If the user attempts to start a dgb or "run with out debugging" session
before PSES is running, a NullRefEx occurs in PSES. Ideally, we would
wait in the resolveDebugConfiguration method for PSES to finish
initializing with a max wait time of say 10 seconds.  Unfortunately,
"sleep" in a loop in JavaScript is not so easy.  AFAIT requires a
significant rewrite of the method using setTimeout().  Not sure it is
worth it, unless someone more knowledgable in JS can find an easy
way to do the poll (for sessionstatus)/sleep loop.

BTW there is probably a fix we need to make in PSES to check if
SynchronizationContext is not null before we try to use it.
@TylerLeonhardt
Copy link
Member

I'd rather just indicate that it's not ready yet. I think that's a reasonable approach/response considering it's rare people run into this.

I also really like the words on that warning!

@TylerLeonhardt
Copy link
Member

Awesome investigation, Keith!

rkeithhill added a commit that referenced this issue Jul 16, 2018
…1436)

Fix #1433

One minor issue is that if you abort (return null|undefined) from
resolveDebugConfiguration, VSCode "helpfully" opens your launch.json
file for you.  Actually, that is quite annoying. I found an issue and on
this and voted it up - microsoft/vscode#54213

Also fix logic for "attach" error.  We only need to test if
OS != Windows.  If on Windows, PS Core supports attach. And tweaked the
error message wording to make more clear.

If the user attempts to start a dgb or "run with out debugging" session
before PSES is running, a NullRefEx occurs in PSES. Ideally, we would
wait in the resolveDebugConfiguration method for PSES to finish
initializing with a max wait time of say 10 seconds.  Unfortunately,
"sleep" in a loop in JavaScript is not so easy.  AFAIT requires a
significant rewrite of the method using setTimeout().  Not sure it is
worth it, unless someone more knowledgable in JS can find an easy
way to do the poll (for sessionstatus)/sleep loop.

BTW there is probably a fix we need to make in PSES to check if
SynchronizationContext is not null before we try to use it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants