Skip to content

[Bug] System.Net.HttpListenerException when system browser flow is cancelled (sometimes) #1773

@crmann1

Description

@crmann1

Which Version of MSAL are you using ?
MSAL 4.11

Platform
net45

What authentication flow has the issue?

  • Desktop / Mobile
    System browser

Is this a new or existing app?
visual studio 2019

Repro
Cancel a system browser flow sign in by closing the account settings dialog when the system browser windows is up. This will set the cancellation token to cancelled which is then passed to the ExecuteAsync method.

When a system browser flow is cancelled
Cancel systemWebBrowserCancellation

builder = builder.WithUseEmbeddedWebView(false);
return await builder.ExecuteAsync(systemWebBrowserCancellation).ConfigureAwait(false);

we sometimes get an exception
System.Net.HttpListenerException

System.Net.HttpListenerException: 'The I/O operation has been aborted because of either a thread exit or an application request'

at System.Net.HttpListener.EndGetContext(IAsyncResult asyncResult)
at Microsoft.Identity.Client.Platforms.Shared.DefaultOSBrowser.HttpListenerInterceptor.d__14.MoveNext()
at Microsoft.Identity.Client.Platforms.Shared.Desktop.OsBrowser.DefaultOsBrowserWebUi.d__10.MoveNext()
at Microsoft.Identity.Client.Platforms.Shared.Desktop.OsBrowser.DefaultOsBrowserWebUi.d__7.MoveNext()
at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.d__11.MoveNext()
at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.d__10.MoveNext()
at Microsoft.Identity.Client.Internal.Requests.RequestBase.d__14.MoveNext()
at Microsoft.Identity.Client.ApiConfig.Executors.PublicClientExecutor.d__2.MoveN

Expected behavior
Could MSAL translate this into a operation cancelled exception if the cancellation token is cancelled.

An operation cancelled exception should be thrown instead if the cancellation token was cancelled and the httplistenerexception was due to that condition.

Actual behavior
A clear and concise description of what happens, e.g. exception is thrown, UI freezes

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions