Skip to content

PowerShell Editor Services terminating error trying to access external USB recycle bin #813

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
Bluecakes opened this issue Jun 1, 2017 · 1 comment · Fixed by PowerShell/PowerShellEditorServices#480
Labels
Issue-Bug A bug to squash.
Milestone

Comments

@Bluecakes
Copy link

Bluecakes commented Jun 1, 2017

Hey PowerShell extension team,

Thanks so much for the brilliant extension for PowerShell support in Visual Studio Code, i seem to be having a weird error in which the PowerShell Editor Services is trying to access one of the folders under the $RECYCLE.BIN folder in my external usb drive (Which being a system folder is denied access to pretty much everyone but the system).

I am able to reproduce this error on the latest 1.2.0 version of the PowerShell extension, please see the details below and let me know if you'd like any additional info.

Steps to reproduce

I have enabled verbose logging and reproduced the issue a few time to generate some verbose logs, please find those zipped and attached here -> logs.zip

  1. Open Visual Studio Code
  2. File -> Open Folder -> Select E:\
  3. Create a new document (Ctrl + N)
  4. Paste the following code
	foreach ($domain in "testlab01.contoso.com", "testlab02.contoso.com")
	{
		$namingContext = $(get-adrootdse -server $domain).defaultnamingcontext
		$computers = Get-ADComputer -Server $domain -Properties lastlogondate, pwdlastset, distinguishedname, operatingsystem, extensionattribute1 -ldapfilter "(&(!operatingSystem=*server*)(operatingSystem=*))"
		
		$countdelete = 0
		
		foreach ($Computer in $computers)
		{
		}
	}
  1. Right click on $computers and select the Find All References option

If i close Visual Studio Code completely or press Ctrl + Shift + P and choose Reload Window and follow the Steps to reproduce the terminating error reoccurs.

Once the error occurs, all PowerShell extension features stop working (Intellisense, PSScriptAnalyzer etc) until i either reload the window or close and reopen Visual Studio Code.

If i continue using Visual Studio Code after the error has occured, about a minute later Visual Studio Code will show an error up the top that says

The PowerShell session has terminated due to an error, would you like to restart it? Yes No Close

Oddly enough, if i follow the Steps to reproduce and skip step 2 the issue does not occur.

Expected behavior

Peek window should come up showing a reference to "foreach ($computer in $computers)"

Actual behavior

Peek window shows up with the text "Loading" and never finishes loading
Terminal shows the following error

PowerShell Integrated Console

PS E:\>

A terminating error occurred in PowerShell Editor Services:

One or more errors occurred.
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.WaitForExit()
   at CallSite.Target(Closure , CallSite , Object )
One or more errors occurred.

Access to the path 'e:\$RECYCLE.BIN\S-1-5-21-1296309925-1638090579-3947801505-1001' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.AddSearchableDirsToStack(SearchData localSearchData)
   at System.IO.FileSystemEnumerableIterator`1.MoveNext()
   at Microsoft.PowerShell.EditorServices.Workspace.<EnumeratePSFiles>d__14.MoveNext()
   at Microsoft.PowerShell.EditorServices.LanguageService.<FindReferencesOfSymbol>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Protocol.Server.LanguageServer.<HandleReferencesRequest>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc)
   at System.Threading.Tasks.Task.Execute()

Environment data

Visual Studio Code 1.12.2
Shell 1.6.6
Renderer 56.0.2924.87
Node 7.4.0

Extensions
Auto Fold 1.0.6
C# 1.10.0
C# XML Documentation Comments 0.0.15
Git History 0.2.0
PowerShell 1.2.0
VSCode Simpler icons with Angular 1.3.0

Powershell PSVersionTable output

PS E:\> $PSVersionTable

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


PS E:\>
@daviwil
Copy link
Contributor

daviwil commented Jun 1, 2017

Hey @Bluecakes, thanks for the report! Seems like we aren't handling access denied exceptions correctly when we traverse the workspace path to find symbol references. Since you've used a top-level path as your workspace path, we seem to be digging into that drive's Recycle Bin folder.

Should be a simple fix, just need to catch that exception and ignore the files in that folder. I'll get it fixed for tomorrow's patch update!

daviwil added a commit to daviwil/PowerShellEditorServices that referenced this issue Jun 1, 2017
This change fixes an issue where the Workspace's file enumeration logic
would throw an UnauthorizedAccessException when it encounters an
unaccessible file or path.  The fix is to make the file enumeration code
more robust so that it catches these exceptions and continues
enumerating as far as it can.

Resolves PowerShell/vscode-powershell#813.
daviwil added a commit to PowerShell/PowerShellEditorServices that referenced this issue Jun 1, 2017
This change fixes an issue where the Workspace's file enumeration logic
would throw an UnauthorizedAccessException when it encounters an
unaccessible file or path.  The fix is to make the file enumeration code
more robust so that it catches these exceptions and continues
enumerating as far as it can.

Resolves PowerShell/vscode-powershell#813.
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

Successfully merging a pull request may close this issue.

2 participants