OneGet / oneget

PackageManagement (aka OneGet) is a package manager for Windows
MIT License
2.38k stars 189 forks source link

Fix deadlock when getting parameters in an event #474

Closed rjmholt closed 5 years ago

rjmholt commented 5 years ago

Fix from @SeeminglyScience:

When getting dynamic parameters from a thread other than the pipeline thread, the call to CommandInfo.Parameters internally tries to get back to it using the PowerShell EventManager. If dynamic parameters are being obtained from an event that is being processed by the EventManager then a deadlock will occur.

This change routes the call to CommandInfo.Parameters to the main thread using AsyncCmdlet.ExecuteOnMainThread, bypassing the EventManager.

I've taken a look at this, and it feels like it's the right fix and doesn't touch too much.

Happy to take responsibility for it.