PowerShell / PowerShell/vscode-powershell

'Safe handle has been closed' when stopping debugger while in a dynamicparam section in v2.2

Open
#3,751 14 comments 0 reactions 1 assignee View on GitHub

@andyleejordan is already working on this.

Since Feb 3, 2022.

Area-Debugging Issue-Bug
Dominant language
TypeScript
Stars
1.9k
Forks
547
PR merge metrics
No merged PRs in 30d

Description

Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.
Exception report
Last 200 Keys:

<omitted irrelevant keystrokes>
 f o o Spacebar - b Tab

### Exception

System.ObjectDisposedException: Safe handle has been closed
   at System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Int32 millisecondsTimeout, Boolean exitContext, Boolean WaitAll)
   at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles, Int32 millisecondsTimeout, Boolean exitContext)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKey()
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)
Screenshot

N/A

Environment data
PS Version: 5.1.19041.1320
PS HostName: Visual Studio Code Host
PSReadLine Version: 2.2.0-beta4
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 227
BufferHeight: 28
Steps to reproduce
  • Use VS Code with PowerShell Preview 2021.12.0 extension
  • Create a function with dynamic parameters, e.g.:
function foo
{
    [CmdletBinding()]
    param ()

    dynamicparam
    {
        $DynParams = [Management.Automation.RuntimeDefinedParameterDictionary]::new()

        $DynParam = [Management.Automation.RuntimeDefinedParameter]::new(
            'bar',
            [string],
            [Collections.ObjectModel.Collection[System.Attribute]]::new()
        )

        $DynParams.Add($DynParam.Name, $DynParam)

        return $DynParams
    }
}
  • Put a breakpoint within the dynamicparam block and start an interactive session
  • Invoke the dynamic parameter with foo - and hit <tab>
  • Debugger stops in the dynamicparam block, as expected
  • Stop the debugger with <Ctrl-F5>
  • Integrated console returns, but shows error message
Expected behavior

No exception

Actual behavior

Error shown

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.