Skip to content

Extension constantly crashes #1652

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
rudfoss opened this issue Dec 12, 2018 · 12 comments
Closed

Extension constantly crashes #1652

rudfoss opened this issue Dec 12, 2018 · 12 comments
Labels
Issue-Bug A bug to squash.

Comments

@rudfoss
Copy link

rudfoss commented Dec 12, 2018

System Details Output

### System Details

### VSCode version: 1.29.1 bc24f98b5f70467bc689abf41cc5550ca637088e x64

### VSCode extensions:
[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]


### PSES version:

### PowerShell version:

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

Issue Description

I'm developing PowerShell scripts that connect to Azure (Using -Az modules). When I start up VSCode the extension starts, but after a short while it "terminates due to an error". I can restart it and it runs for a bit before suddenly crashing again. I've been unable to correlate it with anything I'm doing as it has happened both when editing a ps1 file as well as a JSON file. It also sometimes happens when the window doesn't even have focus or when closing tabs.

Expected Behaviour

It should not crash randomly

Actual Behaviour

It crashes randomly

Attached Logs

powershell-logs-1544625128-a7a83b7d-26c9-4a04-bf94-4ab6cb8606fc1544625123928.zip

@rudfoss rudfoss changed the title The PowerShell session has terminated due to an error almost constantly Extension constantly crashes Dec 12, 2018
@rjmholt
Copy link
Contributor

rjmholt commented Dec 12, 2018

This looks like the relevant problem:

2018-12-12 15:32:14.511 [ERROR] tid:11 in 'OnListenTaskCompleted' C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs: line 391
    ProtocolEndpoint message loop terminated due to unhandled exception:
    
    System.AggregateException: One or more errors occurred. ---> System.ArgumentException: Item has already been added. Key in dictionary: 'c:\Users\Thomas Rudfoss\Projects\MONO-Web\packages\shared-iac\scripts\Start-VeracityAzProvisioning.ps1'  Key being added: 'c:\Users\Thomas Rudfoss\Projects\MONO-Web\packages\shared-iac\scripts\Start-VeracityAzProvisioning.ps1'
       at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
       at System.Collections.Specialized.OrderedDictionary.Add(Object key, Object value)
       at Microsoft.PowerShell.EditorServices.LanguageService.<FindReferencesOfSymbol>d__18.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.CodeLenses.ReferencesCodeLensProvider.<ResolveCodeLensAsync>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.CodeLenses.CodeLensFeature.<HandleCodeLensResolveRequest>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
       at System.Threading.Tasks.Task.Execute()
       --- End of inner exception stack trace ---
    ---> (Inner Exception #0) System.ArgumentException: Item has already been added. Key in dictionary: 'c:\Users\Thomas Rudfoss\Projects\MONO-Web\packages\shared-iac\scripts\Start-VeracityAzProvisioning.ps1'  Key being added: 'c:\Users\Thomas Rudfoss\Projects\MONO-Web\packages\shared-iac\scripts\Start-VeracityAzProvisioning.ps1'
       at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
       at System.Collections.Specialized.OrderedDictionary.Add(Object key, Object value)
       at Microsoft.PowerShell.EditorServices.LanguageService.<FindReferencesOfSymbol>d__18.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.CodeLenses.ReferencesCodeLensProvider.<ResolveCodeLensAsync>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.CodeLenses.CodeLensFeature.<HandleCodeLensResolveRequest>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
       at System.Threading.Tasks.Task.Execute()<---
    

2018-12-12 15:32:14.511 [ERROR] tid:11 in 'ProtocolEndpoint_UnhandledException' C:\PowerShellEditorServices\src\PowerShellEditorServices.Host\EditorServicesHost.cs: line 448
    PowerShell Editor Services is terminating due to an unhandled exception, see previous logs for details.

Looks like we've counted a referenced file twice, possibly because there are multiple references to it in different ways. Shouldn't be too hard to fix.

As a workaround @rudfoss, try commenting out any dot-sourcing and imports. If you add them back in one at a time and you get a crash, we've found our culprit.

@rjmholt rjmholt added Issue-Bug A bug to squash. Area-General labels Dec 12, 2018
@rudfoss
Copy link
Author

rudfoss commented Dec 13, 2018

Great, thanks for your help! I know I have duplicate references so that's probably it. I tried to comment out the references and include them back one by one, but it doesn't appear to consistently crash the extension. Do I have to re-open the file for each import?

Edit: The last file before the stack trace in the log seems to always be the same file though it has no dot-sourced references at all on it's own and is only referenced by one other ps1 file.

@jkavanagh58
Copy link

I unsuccessfully filed an issue using the VSCode tool abut it was about the PowerShell console crashing frequently and is easily reproduceable by creating a new file, change the file type from PowerShell (that is set as my default language) to Plain Text. Does this fit within this issue or do I need to file a new one? Thanks

@rjmholt
Copy link
Contributor

rjmholt commented Dec 17, 2018

@jkavanagh58 that sounds like #1649.

@jkavanagh58
Copy link

jkavanagh58 commented Dec 18, 2018

So the key is not accept the standard behavior of VSCode when doing a basic Ctrl+N? I will have to see if I can change that in settings. If the problem is because the file name that VSCode creates then maybe fix the issue or change the filename it creates?

@rjmholt
Copy link
Contributor

rjmholt commented Dec 18, 2018

So the key is not accept the standard behavior of VSCode when doing a basic Ctrl+N? I will have to see if I can change that in settings. If the problem is because the file name that VSCode creates then maybe fix the issue or change the filename it creates?

It's not the file name, it's that it's an in-memory file, which lives under the untitled: URI scheme rather than the file: URI scheme. When you create a new file in VSCode it lives in memory until it saves it to the file system.

The PowerShell extension tries very hard to make this abstraction work by building the same file in memory in its own process, but a reference-resolver update we took last release broke one of the code paths unfortunately because it assumed that all files live on the file system.

We've now merged a PR to fix this.

@rjmholt
Copy link
Contributor

rjmholt commented Dec 18, 2018

If you want a workaround, you should save the file with a PowerShell file extension and then start using it.

@jkavanagh58
Copy link

Well @rjmholt I was seeing this (ironic but while demonstrating VSCode as a great tool) by creating a new file for pasting a large list of text and then changing the language from PowerShell to Plain Text. It was a demonstration of the multi-line editing (take a bunch of strings and wrapping them in quotes or whatever). I can wait for the fix sir.

@rjmholt
Copy link
Contributor

rjmholt commented Dec 18, 2018

changing the language from PowerShell to Plain Text

You may have "files.defaultLanguage" set to PowerShell.

Try removing that.

@hypercube33
Copy link

I'm getting the same error now and was not before on the same file i've been working on for weeks.

`2019-04-08 16:50:24.366 [NORMAL] tid:14 in 'StartLogging' C:\PowerShellEditorServices\src\PowerShellEditorServices.Host\EditorServicesHost.cs: line 183

PowerShell Editor Services Host v1.12.0.0 starting (PID 6228

  Host application details:

    Name:      Visual Studio Code Host
    Version:   1.12.0
    ProfileId: Microsoft.VSCode
    Arch:      X64

  Operating system details:

    Version: Microsoft Windows 10.0.16299 
    Arch:    X64

  Build information:

    Version: <development-build>
    Origin:  <development>
    Date:    2019-03-29T16:36:28

2019-04-08 16:50:24.377 [NORMAL] tid:14 in 'StartLanguageService' C:\PowerShellEditorServices\src\PowerShellEditorServices.Host\EditorServicesHost.cs: line 202
Language service started, type = NamedPipe, endpoint = InOut pipe: PSES_t3nvqt3o.d2t
2019-04-08 16:50:24.377 [NORMAL] tid:14 in 'StartDebugService' C:\PowerShellEditorServices\src\PowerShellEditorServices.Host\EditorServicesHost.cs: line 279
Debug service started, type = NamedPipe, endpoint = InOut pipe: PSES_ugpmxmje.akt
2019-04-08 16:50:24.489 [NORMAL] tid:4 in 'Initialize' C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: line 221
PowerShell runtime version: 5.1.16299.1004, edition: Desktop
2019-04-08 16:50:25.005 [NORMAL] tid:19 in 'Register' C:\PowerShellEditorServices\src\PowerShellEditorServices.VSCode\ComponentRegistration.cs: line 36
PowerShell Editor Services VS Code module loaded.
2019-04-08 16:50:26.201 [ERROR] tid:4 in 'OnListenTaskCompleted' C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs: line 391
ProtocolEndpoint message loop terminated due to unhandled exception:

System.AggregateException: One or more errors occurred. ---> System.NotSupportedException: The given path's format is not supported.
   at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
   at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
   at Microsoft.PowerShell.EditorServices.Workspace.ResolveFilePath(String filePath)
   at Microsoft.PowerShell.EditorServices.Workspace.GetFile(String filePath)
   at Microsoft.PowerShell.EditorServices.CodeLenses.CodeLensFeature.<HandleCodeLensResolveRequest>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.NotSupportedException: The given path's format is not supported.
   at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
   at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
   at Microsoft.PowerShell.EditorServices.Workspace.ResolveFilePath(String filePath)
   at Microsoft.PowerShell.EditorServices.Workspace.GetFile(String filePath)
   at Microsoft.PowerShell.EditorServices.CodeLenses.CodeLensFeature.<HandleCodeLensResolveRequest>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
   at System.Threading.Tasks.Task.Execute()<---

2019-04-08 16:50:26.202 [ERROR] tid:4 in 'ProtocolEndpoint_UnhandledException' C:\PowerShellEditorServices\src\PowerShellEditorServices.Host\EditorServicesHost.cs: line 448
PowerShell Editor Services is terminating due to an unhandled exception, see previous logs for details.
`

@hypercube33
Copy link

Looks like when its trying to format text (or I see text move right before it crashes) it'll trigger the crash

@rjmholt
Copy link
Contributor

rjmholt commented Apr 8, 2019

@hypercube33 you are experiencing #1830

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash.
Projects
None yet
Development

No branches or pull requests

4 participants