Skip to content

AMSI not uninitialized when pwsh is not crossgen'd and the window hosting pwsh (directly or indirectly) gets closed (on Windows) #6862

@bergmeister

Description

@bergmeister

This is either a bug or a Debug.Assert call needs to be reviewed. The VerifyAmsiUninitializeCalled method that is called here has a Debug.Assert violation in the following scenario:

  • Debug build (because Debug.Assert is only enabled in Debug)
  • The -CrossGen option on Start-PSBuild is not used
  • The ConsoleHost gets closed by the window that is hosting pwsh (can be directly or indirectly, i.e. nested) via the Windows UI (Close button on the window itself or the taskbar) but not via typing exit

Steps to reproduce

git clone https://github.com/PowerShell/PowerShell.git PowerShellReproIssue6862
cd .\PowerShellReproIssue6862
Import-Module .\build.psm1
Start-PSBootStrap
Start-PSBuild
Invoke-Item "$pwd/src\powershell-win-core\bin\Debug\netcoreapp2.1\win7-x64\publish\pwsh.exe"
# Then close the window via the `X` button or the `Close` option on the taskbar

Expected behavior

The window closes normally.

Actual behavior

Debug.Assert failure here
image

Environment data

(Latest state of master)

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta.3
PSEdition                      Core
GitCommitId                    v6.0.0-beta.3-1131-gd07a3e7c2faf3f3489ae80e17cb2f02533c392e6
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Code Cleanupthe issue is for cleaning up the code with no impact on functionalityWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions