microsoft-authentication-library-for-dotnet icon indicating copy to clipboard operation
microsoft-authentication-library-for-dotnet copied to clipboard

[Bug] ObjectDisposedException crashes app using WindowsFormsWebAuthenticationDialog

Open ryanmolden opened this issue 1 year ago • 0 comments

Library version used

4.61.3

.NET version

net462

Scenario

PublicClient - desktop app

Is this a new or an existing app?

The app is in production, and I have upgraded to a new version of MSAL

Issue description and reproduction steps

This is a crash in Perfview. Specifically, this (abbreviated, simplified) callstack tries to show a dialog:

<snip>
mscorlib_ni!System.ObjectDisposedException..ctor()
System_Windows_Forms_ni!System.Windows.Forms.Control.DestroyHandle(...)
System_Windows_Forms_ni!System.Windows.Forms.Form.ShowDialog(...)
System_Windows_Forms_ni!System.Windows.Forms.Form.ShowDialog(...)
Microsoft_Identity_Client!Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WindowsFormsWebAuthenticationDialog.<>c__DisplayClass5_0.<ShowBrowser>b__0(...)
Microsoft_Identity_Client!Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WindowsFormsWebAuthenticationDialogBase.InvokeHandlingOwnerWindow(...)
Microsoft_Identity_Client!Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.WindowsFormsWebAuthenticationDialog.ShowBrowser(...)
<snip>

In doing so it decides it already has created an HWND (not sure why, this is the first time it tried to show me any authentication dialog). Because of that it creates an ObjectDisposedException (but does not throw it).

It then queues the ObjectDisposedException as a result for anyone waiting on UI thread callbacks registered through the control (presumably because they were tied to the window it is about to destroy).

Then, one such callback encounters the exception, it is thrown, and crashes PerfView along this (abbreviated, simplified) callstack:

KERNELBASE!RaiseException(...)
clr!RaiseTheExceptionInternalOnly(...)
clr!IL_Throw(...)
mscorlib_ni!System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(...)
mscorlib_ni!System.Threading.CancellationTokenSource.NotifyCancellation(...)
mscorlib_ni!System.Threading.CancellationTokenSource.TimerCallbackLogic(...)
mscorlib_ni!System.Threading.ExecutionContext.RunInternal(...)
mscorlib_ni!System.Threading.ExecutionContext.Run(...)
mscorlib_ni!System.Threading.TimerQueueTimer.CallCallback(...)
mscorlib_ni!System.Threading.TimerQueueTimer.Fire(...)
mscorlib_ni!System.Threading.TimerQueue.FireNextTimers(...)
<snip>

I am MSFT internal and have heap dumps both when the ODE is created and when the app crashes due to it getting thrown and no one handling it. You can contact me internally at rmolden.

Relevant code snippets

No response

Expected behavior

Not to crash the app using the dialog

Identity provider

Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)

Regression

No response

Solution and workarounds

No response

ryanmolden avatar Sep 11 '24 19:09 ryanmolden