FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Unregister-Event inside its own action deadlocks the interactive prompt (input is never read) · Issue #28379 · PowerShell/PowerShell · GitHub

Repository navigation

Unregister-Event inside its own action deadlocks the interactive prompt (input is never read) #28379

Open

Description

Prerequisites

Steps to reproduce

Add this to $PROFILE and start pwsh:

$a = { Unregister-Event -SourceIdentifier PowerShell.OnIdle }
Register-EngineEvent PowerShell.OnIdle -Action $a | Out-Null
Register-EngineEvent PowerShell.OnIdle -Action $a | Out-Null

Then type anything at the first prompt. Nothing is echoed.

A single registration does not reproduce; two do. This matches the note in #16154 that
the hang needs another action pending when Unregister-Event runs.

The real-world session that led to this report showed the same stack: the process was
alive at 0% CPU with 110 bytes of keystrokes queued in the tty input buffer.

Expected behavior

Unregister-Event returns and the prompt keeps accepting input.

Actual behavior

The shell stops reading stdin. The process stays alive at ~0% CPU, the tty is in raw
mode, and the tty input queue accumulates typed bytes. The session has to be killed.

Error details

Managed stack of the pipeline thread (sample plus DOTNET_PerfMapEnabled, pwsh 7.6.9):

PSConsoleReadLine.ReadLine
  PSConsoleReadLine.InputLoop
    PSConsoleReadLine.ReadKey
      PowerShell.Invoke
        PSLocalEventManager.ProcessPendingActionsImpl
          PSLocalEventManager.InvokeAction
            PSEventJob.Invoke
              ScriptBlock.InvokeWithPipe
                UnregisterEventCommand.ProcessRecord
                  PSLocalEventManager.UnsubscribeEvent
                    PSLocalEventManager.DrainPendingActions
                      Thread.Sleep(int32)   # waits for the action that is itself running

Because the action is dispatched from inside PSConsoleReadLine.ReadKey, blocking the
pipeline thread also stops terminal input from being read.

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.9
PSEdition                      Core
GitCommitId                    7.6.9
OS                             macOS 27.2.0
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

N/A

Related: #16154

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL