Skip to content

Hangs on ArgumentCompleter Debugging #3256

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
JustinGrote opened this issue Jan 19, 2021 · 20 comments
Closed

Hangs on ArgumentCompleter Debugging #3256

JustinGrote opened this issue Jan 19, 2021 · 20 comments
Labels
Area-Debugging Issue-Bug A bug to squash. Needs: Fix Verification Please verify the fix for us! Resolution-Fixed Will close automatically.

Comments

@JustinGrote
Copy link
Collaborator

Example Code:

using namespace System.Management.Automation
$MSIHelper = {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)

    if ($GLOBAL:ACDebug) {
        $CommandName | Write-Host -fore darkgreen
        $ParameterName | Write-Host -fore darkcyan
        $wordToComplete | Write-Host -fore darkyellow
        $commandAst | ft | Out-String | Write-Host -fore magenta
        $fakeBoundParameters | ft | out-string | write-host -fore green
    }
    [CompletionResult]::new(
        'test', #completionText
        'testListItem', #listItemText
        [CompletionResultType]::ParameterValue, #resultType
        'testToolTip' #toolTip
    )
}
Register-ArgumentCompleter -CommandName New-AzureADServiceAppRoleAssignment -ScriptBlock $MSIHelper

When dotsourcing this from a file and then starting interactive debug with F5, upon attempting the completion it starts debug and stops at the correct line and displays all the info, however the console is hung and none of the debug buttons (run, step into/out/etc) work. Stop does work, but the integrated console totally hangs and requires a restart.
image

@SydneyhSmith SydneyhSmith transferred this issue from PowerShell/PowerShellEditorServices Mar 23, 2021
@ghost ghost added the Needs: Triage Maintainer attention needed! label Mar 23, 2021
@SydneyhSmith SydneyhSmith added Area-Debugging Issue-Bug A bug to squash. and removed Needs: Triage Maintainer attention needed! labels Mar 23, 2021
@babysnakes
Copy link

Same problem here 🙁

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jan 29, 2022
@andyleejordan
Copy link
Member

@JustinGrote Do you know if this continues to repro with the latest Preview? @babysnakes What version of the extension are you using?

@andyleejordan andyleejordan added Needs: Author Feedback Please give us the requested feedback! and removed Needs: Maintainer Attention Maintainer attention needed! labels Jan 31, 2022
@babysnakes
Copy link

babysnakes commented Jan 31, 2022

@andschwa , I'm using current latest (2021.12.0).

Thanks

EDIT: forgot to mention, I'm using PowerShell 7.2 on windows 10.

@ghost ghost added Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Author Feedback Please give us the requested feedback! labels Jan 31, 2022
@andyleejordan
Copy link
Member

@babysnakes Can you try the latest version of PowerShell Preview for VS Code? Thanks again!

@babysnakes
Copy link

@andschwa sure, I'll try tomorrow and update.

@StevenBucher98 StevenBucher98 added Needs: Author Feedback Please give us the requested feedback! and removed Needs: Maintainer Attention Maintainer attention needed! labels Feb 1, 2022
@babysnakes
Copy link

@andschwa, Sorry it took me some time 🙁 ...

I installed the latest preview, Imported the completion from file and tried to debug completions. The good news is that I was able to step the debugger. It doesn't seem to produce completion back to the terminal but it's a good start 😄.

Here's the entire output from the terminal:

=====> PowerShell Preview Integrated Console v2022.2.0 <=====

PS C:\Users\haim\Code\Personal\test> Import-Module .\file.ps1
PS C:\Users\haim\Code\Personal\test> asdfw [DBG]: PS C:\Users\haim\Code\Personal\test>
[DBG]: PS C:\Users\haim\Code\Personal\test> 

Oops, something went wrong.
Please report this bug with ALL the details below, including both the 'Environment' and 'Exception' sections.
Please report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new?template=Bug_Report.yaml        
Thank you!

### Environment
PSReadLine: 2.2.0-beta5
PowerShell: 2022.2.0
OS: Microsoft Windows 10.0.19044
BufferWidth: 128
BufferHeight: 11

Last 25 Keys:

 i m p o r t - m o d u Tab Spacebar f i l Tab Enter
 a s d f w Spacebar Tab

### Exception

System.ObjectDisposedException: Safe handle has been closed.
Object name: 'SafeHandle'.
   at System.Runtime.InteropServices.SafeHandle.InternalRelease(Boolean disposeOrFinalizeOperation)
   at System.Runtime.InteropServices.SafeHandle.DangerousRelease()
   at System.Threading.WaitHandle.ObtainSafeWaitHandles(ReadOnlySpan`1 waitHandles, Span`1 safeWaitHandles, Span`1 unsafeWaitHandles)
   at System.Threading.WaitHandle.WaitMultiple(ReadOnlySpan`1 waitHandles, Boolean waitAll, Int32 millisecondsTimeout)
   at System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Boolean waitAll, Int32 millisecondsTimeout)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKey()
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)


PS C:\Users\haim\Code\Personal\test> asdfw he[DBG]: PS C:\Users\haim\Code\Personal\test> 
[DBG]: PS C:\Users\haim\Code\Personal\test>
[DBG]: PS C:\Users\haim\Code\Personal\test>
[DBG]: PS C:\Users\haim\Code\Personal\test>
[DBG]: PS C:\Users\haim\Code\Personal\test>
[DBG]: PS C:\Users\haim\Code\Personal\test>
[DBG]: PS C:\Users\haim\Code\Personal\test>
[DBG]: PS C:\Users\haim\Code\Personal\test> 

Oops, something went wrong.
Please report this bug with ALL the details below, including both the 'Environment' and 'Exception' sections.
Please report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new?template=Bug_Report.yaml
Thank you!

### Environment
PSReadLine: 2.2.0-beta5
PowerShell: 2022.2.0
OS: Microsoft Windows 10.0.19044
BufferWidth: 128
BufferHeight: 11

Last 34 Keys:

 i m p o r t - m o d u Tab Spacebar f i l Tab Enter
 a s d f w Spacebar Tab a s d f w Spacebar h e Tab

### Exception

System.ObjectDisposedException: Safe handle has been closed.
Object name: 'SafeHandle'.
   at System.Runtime.InteropServices.SafeHandle.InternalRelease(Boolean disposeOrFinalizeOperation)
   at System.Threading.WaitHandle.ObtainSafeWaitHandles(ReadOnlySpan`1 waitHandles, Span`1 safeWaitHandles, Span`1 unsafeWaitHandles)
   at System.Threading.WaitHandle.WaitMultiple(ReadOnlySpan`1 waitHandles, Boolean waitAll, Int32 millisecondsTimeout)
   at System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Boolean waitAll, Int32 millisecondsTimeout)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKey()
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)

@andyleejordan
Copy link
Member

Ah ha, that's super useful @babysnakes, it looks like the same thing we're seeing in #3751. Seems like the way we're invoking PSReadLine barfs if it happens under the debugger while it's in the middle of doing something.

@babysnakes
Copy link

@andschwa , glad I could help. Let me know if there's anything else you want me to try.

@andyleejordan andyleejordan moved this from Todo to In Progress in Sea Biscuit Feb 9, 2022
@andyleejordan
Copy link
Member

Ditto #3751 (comment) @babysnakes and @JustinGrote. Can you try again?

@andyleejordan andyleejordan added Needs: Fix Verification Please verify the fix for us! Resolution-Fixed Will close automatically. and removed Needs: Author Feedback Please give us the requested feedback! labels Feb 9, 2022
@andyleejordan
Copy link
Member

Marking as fixed, if it does still repro, please let me know, and re-open it!

@ghost ghost closed this as completed Feb 9, 2022
@ghost
Copy link

ghost commented Feb 9, 2022

This issue has been marked as fixed. It has been automatically closed for housekeeping purposes.

Repository owner moved this from In Progress to Done in Sea Biscuit Feb 9, 2022
@babysnakes
Copy link

@andschwa, I don't see any new plugin version (or github release). The last one is from over a week ago (02/02/22 - v2022.2.0). Is there going to be a new preview release soon?

@andyleejordan
Copy link
Member

andyleejordan commented Feb 10, 2022

Yes, that version of the PowerShell Preview extension is what I tested. It has the fix I mentioned (PowerShell/PowerShellEditorServices#1690) and I can no longer repro this bug report (where I could previously).

@babysnakes
Copy link

@andschwa, here's the output from the debugging completion terminal. It's similar to before. Note that the current state of debugging completion script is good enough for me. I don't need the output to be printed to the console:

=====> PowerShell Preview Integrated Console v2022.2.0 <=====

PS C:\Users\haim\Code\Personal\roon-tagger> ipmo .\src\RoonTagger.Cli\Resources\Completions\roon-tagger-completion.ps1
PS C:\Users\haim\Code\Personal\roon-tagger> roon-tagger c[DBG]: PS C:\Users\haim\Code\Personal\roon-tagger> 
[DBG]: PS C:\Users\haim\Code\Personal\roon-tagger> 
[DBG]: PS C:\Users\haim\Code\Personal\roon-tagger> 
[DBG]: PS C:\Users\haim\Code\Personal\roon-tagger> 

Oops, something went wrong.
Please report this bug with ALL the details below, including both the 'Environment' and 'Exception' sections.
Please report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new?template=Bug_Report.yaml
Thank you!

### Environment
PSReadLine: 2.2.0-beta5
PowerShell: 2022.2.0
OS: Microsoft Windows 10.0.19044
BufferWidth: 115
BufferHeight: 11

Last 56 Keys:

 i m Backspace p m o Spacebar s r Tab r o Tab r e s Tab c o m Tab Tab Enter
 r o o n - t a g g e r Spacebar c Tab Tab Tab Ctrl+u Ctrl+a Backspace r o o n - t a g g e r Spacebar c Tab

### Exception

System.ObjectDisposedException: Safe handle has been closed.
Object name: 'SafeHandle'.
   at System.Runtime.InteropServices.SafeHandle.InternalRelease(Boolean disposeOrFinalizeOperation)
   at System.Runtime.InteropServices.SafeHandle.DangerousRelease()
   at System.Threading.WaitHandle.ObtainSafeWaitHandles(ReadOnlySpan`1 waitHandles, Span`1 safeWaitHandles, Span`1 
unsafeWaitHandles)
   at System.Threading.WaitHandle.WaitMultiple(ReadOnlySpan`1 waitHandles, Boolean waitAll, Int32 millisecondsTimeout)
   at System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Boolean waitAll, Int32 millisecondsTimeout)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKey()
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)


PS C:\Users\haim\Code\Personal\roon-tagger> 
PS C:\Users\haim\Code\Personal\roon-tagger>

@andyleejordan
Copy link
Member

@babysnakes Can you share the script you're debugging that's causing that?

@babysnakes
Copy link

@andschwa sure. here.

@andyleejordan
Copy link
Member

Screen Shot 2022-02-10 at 12 43 07 PM

Working fine so far.

@andyleejordan
Copy link
Member

Ah ha, on pressing Continue it errors:

> roon-tagger credits --a[DBG] @andys-mac-mini ~/src 
>      

Oops, something went wrong.
Please report this bug with ALL the details below, including both the 'Environment' and 'Exception' sections.
Please report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new?template=Bug_Report.yaml
Thank you!

### Environment
PSReadLine: 2.2.0-beta5
PowerShell: 2022.2.0
OS: Darwin 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T8101
BufferWidth: 151
BufferHeight: 32

Last 200 Keys:

 Tab Backspace Backspace Backspace - Tab Tab Backspace / s r c / R o o n T a g g e r . C l i / b i n / D e b u g / n e t 5 . 0 / Ctrl+a Ctrl+a Ctrl+f Ctrl+f Ctrl+f Ctrl+f Ctrl+f Ctrl+f Ctrl+f Ctrl+f Ctrl+f Ctrl+f . Enter
 r o o n t - a Backspace Backspace Backspace - t a g Tab Enter
 r o o n - t a g g e r Spacebar - - Tab v Tab Tab s Tab Ctrl+a Ctrl+k r o o n - t a g Tab Spacebar Backspace Ctrl+a Ctrl+k r o o n t Backspace - t a g g e r Spacebar c Tab r Tab Ctrl+a Ctrl+k r o o n - t a g g e r Spacebar c Tab r Tab Spacebar - - Tab c Enter
 c l e a r Enter
 UpArrow UpArrow UpArrow Spacebar c r Tab Spacebar - - a Tab s Backspace Tab Tab Tab Ctrl+u Ctrl+a l s Backspace Ctrl+a Ctrl+e Ctrl+w l k j a d Ctrl+a Ctrl+e Ctrl+a Ctrl+k l k j a Backspace Backspace Backspace Backspace

### Exception

System.ObjectDisposedException: Safe handle has been closed.
Object name: 'SafeHandle'.
   at System.Runtime.InteropServices.SafeHandle.InternalRelease(Boolean disposeOrFinalizeOperation)
   at System.Threading.WaitHandle.ObtainSafeWaitHandles(ReadOnlySpan`1 waitHandles, Span`1 safeWaitHandles, Span`1 unsafeWaitHandles)
   at System.Threading.WaitHandle.WaitMultiple(ReadOnlySpan`1 waitHandles, Boolean waitAll, Int32 millisecondsTimeout)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKey()
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)

@babysnakes
Copy link

@andschwa yeah, sorry, I didn't explain myself correctly ...

@andyleejordan
Copy link
Member

No worries! That's why it's helpful to have enough repro info for me to step through it all. This helps narrow it down. I'll get a debugger attached and see what's happening when I press "Continue" that ReadLine barfs.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Debugging Issue-Bug A bug to squash. Needs: Fix Verification Please verify the fix for us! Resolution-Fixed Will close automatically.
Projects
No open projects
Status: Done
Development

No branches or pull requests

5 participants