| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
I tried to add a test, but I cannot find a way to get the EventHandler methods from the event member AppDomain.ProcessExit ... |
Sorry, something went wrong.
There was a problem hiding this comment.
I wonder that
internal static void WinCloseSession()
and
internal static void WinUninitialize()
is not under #if !UNIX ... #endif
Can we use a global static counter for test?
Sorry, something went wrong.
|
I can get the invocation method list in .NET, but not in .NET Core. The following works in Windows PowerShell $f = [System.AppDomain].GetFields([System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::GetField) | ? name -eq '_processExit'
$v = $f.GetValue([System.AppDomain]::CurrentDomain)
$v.GetInvocationList()
Method Target
------ ------
Void DisposeOnShutdown(System.Object, System.EventArgs)
Void CurrentDomain_ProcessExit(System.Object, System.EventArgs)
Void SingletonDomainUnload(System.Object, System.EventArgs) {System.EventHandler}So at least I can add a test when porting this change to Windows PowerShell. |
Sorry, something went wrong.
|
Hello Dongbo Wang (@daxian-dbw)! Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass. Do note that I've been instructed to only help merge pull requests of this repository that have been opened for at least 24 hours, a condition that will be fulfilled in about 1 hour 59 minutes. No worries though, I will be back when the time is right! 😉 p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here. |
Sorry, something went wrong.
|
Dongbo Wang (@daxian-dbw) I got it ("static" is key): $f = [System.AppContext].GetFields([System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::GetProperty -bor [System.Reflection.BindingFlags]::Static) | ? name -eq 'ProcessExit'
$v = $f.GetValue([System.AppDomain]::CurrentDomain)
# or $f.GetValue([System.AppContext]::ProcessExit)
$v.GetInvocationList() |
Sorry, something went wrong.
|
Ilya (@iSazonov) This is very strange, and feels to me may randomly stop working in future .NET Core 😄 |
Sorry, something went wrong.
|
Dongbo Wang (@daxian-dbw) AppContext is public API and the property is static - it is not likely that this public API will be changed. |
Sorry, something went wrong.
|
Ahh, I thought it was [System.AppDomain]. Just realized you were using [System.AppContext].
This is wrong, should pass in $null as argument. I will submit a test for this change then. |
Sorry, something went wrong.
|
Hmm, I cannot write a Pester test for this, because the leak won't happen as long as a Runspace still opens. Need to do it in xUnit. |
Sorry, something went wrong.
I don't understand your thought. It seem works well in the example I posted. |
Sorry, something went wrong.
|
It's a static field, so should pass null when calling GetValue. Your code works but that may be because the dotnet implementation just ignored the passed in argument, which could change to check for null in future. |
Sorry, something went wrong.
|
Sorry, if I noisy but I always wonder how in-depth you look. |
Sorry, something went wrong.
|
I was not clear in my above statement. Today, you can pass anything to $f.GetValue() when it's a static field. For example: PS:32> $f = [System.AppContext].GetFields([System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::GetProperty -bor [System.Reflection.BindingFlags]::Static) | ? name -eq 'ProcessExit'
PS:33> $f.GetValue("fff")
Target Method
------ ------
Void CurrentDomain_ProcessExit(System.Object, System.EventArgs)
It may be because today the .net implementation ignore the argument when the field is static, but this could change in future so that exception would be thrown if the passed in argument is not null. |
Sorry, something went wrong.
|
Thanks for clarify! |
Sorry, something went wrong.
|
🎉v7.0.0-preview.5 has been released which incorporates this pull request.:tada: Handy links: |
Sorry, something went wrong.
Add a test for the even handler leaking fix addressed in PowerShell#10626 PowerShell#10626 The test is added to verify that PowerShell unregister the 'AppDomain.ProcessExit' event handler when a Runspace closes.
Add a test for the even handler leaking fix addressed in PowerShell#10626 PowerShell#10626 The test is added to verify that PowerShell unregister the 'AppDomain.ProcessExit' event handler when a Runspace closes.
| Back | FazBrowse Home | New Git URL |
PR Summary
Unregister the event handler from AppDomain.CurrentDomain.ProcessExit when uninitializing AMSI.
The event handler was registered when opening a Runspace, but not unregistered when closing.
In the hosting scenario, every time a Runspace is opened/closed, an instance of the EventHandler will be left behind linked to the AppDomain.CurrentDomain. In a dump file provided by a partner team, there are 588017 such EventHandler instances leaked.
PR Checklist