Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eilon/net8 blazor androidhang #22473

Closed
wants to merge 6 commits into from
Closed

Conversation

Eilon
Copy link
Member

@Eilon Eilon commented May 16, 2024

Description of Change

Add an opt-in switch to enable the BlazorWebView to 'fire and forget' the async disposal that occurs in BlazorWebView. By default, the BlazorWebView does async-over-sync for disposal, meaning that it blocks the thread until the async disposal is complete. Unfortunately, this can cause deadlocks if the disposal itself needs to run code on the same thread (because that thread is blocked while waiting). The control has had this logic for a long time, but it seems that on Android the luck has changed, and hangs are now quite common during disposal.

By default there is no behavior change.

If you are encountering hangs in Android with BlazorWebView, you can enable this AppContext Switch with one line of code in your app's MauiProgram.cs:

AppContext.SetSwitch("BlazorWebView.FireAndForgetAsync", isEnabled: true);

This issue has been reported in several different issues, but we think they all have this same root cause, and enabling this new switch should fix your app.

Example reports:

Caveats

Because enabling this new switch means that disposal can return before all objects are disposed, this can cause behavioral changes in an app. The items that are disposed are partially Blazor's own internal types, but also app-defined types such as scoped services used within the BlazorWebView portion of the app.

Issues Fixed

Fixes #13529

@Eilon Eilon added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label May 16, 2024
@Eilon
Copy link
Member Author

Eilon commented May 17, 2024

Closing. Use #22496 instead.

@Eilon Eilon closed this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DisposeAsync() on IJSObjectReference causes hanging when called on Android 11 and lower on app suspension
2 participants