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

[regression/8.0.0] Android app crashes with an ANR on .NET 8 preview 6 #16418

Closed
jmezach opened this issue Jul 28, 2023 · 10 comments
Closed

[regression/8.0.0] Android app crashes with an ANR on .NET 8 preview 6 #16418

jmezach opened this issue Jul 28, 2023 · 10 comments
Labels
external i/regression This issue described a confirmed regression on a currently supported version partner/android Issues for the Android SDK platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Milestone

Comments

@jmezach
Copy link

jmezach commented Jul 28, 2023

Description

We are experiencing an issue with a cross-platform app we are developing that is being killed by Android due to an Application Not Responding (ANR). So far we haven't been able to pinpoint what is causing this, but we figured we'd report this anyway since it appears not to happen with .NET 7, only with .NET 8. That being said, we do have a workaround which is removing the <GoogleServicesJson> element from the project file, but that then means we are unable to receive push notifications in our app which we obviously do actually need.

So it seems that there is some combination of factors that are contributing to this issue but we don't think it is something that is actually happening in our code. We can however consistently reproduce the issue. What is further complicating things is that it only seems to happen when the app is running on a device and has been compiled in Release mode.

We do have an ANR report from a device but it is too big to post here. What would be the best way to provide this information?

Steps to Reproduce

  1. Create a .NET MAUI Android app targeting .NET 8
  2. Add push notification support to the app through Firebase
  3. See the app crash with an ANR
  4. Notice that this does not happen when targeting .NET 7

Please note that our provided repro doesn't actually crash with an ANR, that only happens in our actual app, but we can't figure out what the difference is. Our working assumption is that in our actual app some process that is running in the background is taking up a lot of time and that causes the app to crash.

Link to public reproduction project repository

https://github.com/tristanhollman/MauiApp_FirebaseMessagingNet8

Version with bug

8.0.0-preview.5.8529

Last version that worked well

7.0.86

Affected platforms

Android

Affected platform versions

At least Android 13, might occur on older versions as well but haven't tested

Did you find any workaround?

A workaround is to remove the <GoogleServiceJson> element from the project file, but then push notifications no longer work.

Relevant log output

We do have an ANR report from a device, but it is too big to place here. Please let us know how we can provide this information.
@jmezach jmezach added the t/bug Something isn't working label Jul 28, 2023
@jmezach
Copy link
Author

jmezach commented Aug 1, 2023

We've done some more investigation into this issue by using the profiling instructions provided here. Unfortunately it seems that this is making matters worse, because the app is now killed by the OS even sooner resulting in a broken trace. We've tried this with almost every .NET 8 preview (except for preview 1 since the app immediately crashes at startup with that version) and what we're seeing in the output of dotnet-trace is that the trace is being collected up to about 1,5 MB and then it stops. A few minutes later the app is killed by the OS and dotnet-trace reports Detected a potentially broken trace. Continuing with best-efforts to convert the trace, but resulting speedscope file may contain broken stacks as a result..

If we do the same with .NET 7 we see that the trace keeps on collecting up to 4 MB after which I pressed Enter, but the app just keeps working and is not being killed by the OS at all. So it seems there is definitely an issue with .NET 8.

@samhouts samhouts added the i/regression This issue described a confirmed regression on a currently supported version label Aug 3, 2023
@samhouts samhouts changed the title Android app crashes with an ANR on .NET 8 preview 6 [regression/8.0] Android app crashes with an ANR on .NET 8 preview 6 Aug 3, 2023
@samhouts samhouts added this to the .NET 8 GA milestone Aug 3, 2023
@samhouts samhouts added the partner/android Issues for the Android SDK label Aug 3, 2023
@samhouts
Copy link
Member

samhouts commented Aug 3, 2023

possibly related to #15829

@jonathanpeppers
Copy link
Member

The sample app does this:
image

What steps do I take to see the issue?

On thing I would try here is to run adb shell setprop debug.mono.trace all, which will make the Mono runtime print every method called. Sometime the output is too much, but it might be able to show what methods are involved in causing the ANR.

Does the problem still occur with .NET 8 Preview 7?

@jonathanpeppers jonathanpeppers added the s/needs-info Issue needs more info from the author label Aug 21, 2023
@ghost
Copy link

ghost commented Aug 21, 2023

Hi @jmezach. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@jonathanpeppers
Copy link
Member

Here are some more detailed instructions for debug.mono.trace: #15829 (comment)

@ghost ghost added the s/no-recent-activity Issue has had no recent activity label Aug 25, 2023
@ghost
Copy link

ghost commented Aug 25, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@tristanhollman
Copy link

@jonathanpeppers thank for taking a look at this. The sample app does not work out of the box currently, this is because we removed the connectionstring/keys from the google-services.json file that are used to connect to Firebase.

We'll take a look at using the .NET 8 preview 7 and the debug.mono.trace options after the weekend.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author s/no-recent-activity Issue has had no recent activity labels Aug 26, 2023
@jonathanpeppers jonathanpeppers added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Aug 28, 2023
@ghost
Copy link

ghost commented Aug 28, 2023

Hi @jmezach. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@tristanhollman
Copy link

We have tested with the .NET 8 preview 7 and the good news is the issue seems to be fixed, app no longer crashes with an ANR after upgrading.

The bad news, upgrading to the new preview involved a bit more work than we expected though. At first the app would crash immediately after opening, this only happened on release builds for Android (debug/iOS builds worked fine). The crash occurred due to a System.NotSupportedException: NoMetadataForType exception, which was caused by the changes regarding Source Generation in System.Text.Json and we were deserializing some JSON responses from our backend after starting the app.

We fixed this by adding a new JsonSerializerContext in the app, as specified in the documentation here but we're still not sure why this suddenly broke (and why it only impacted Android).

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Aug 30, 2023
@jonathanpeppers
Copy link
Member

There is a fix for System.Text.Json which will be shipping soon in .NET 8 RC 1:

dotnet/android@05f79c0

You should be able to set $(JsonSerializerIsReflectionEnabledByDefault) for now in your project or opting to use the source generator might be an even better option. If you are seeing general problems with System.Text.Json, you can file issues related to that here.

If that is the only issue you ran into so far using .NET 8 Preview 7, I suspect the original problem could have been related to $(AndroidEnableMarshalMethods):

We disabled this feature in .NET 8 Preview 7 to revisit in .NET 9. I'll add your example to the list, to test in the future.

But sounds like things are working now. Closing, as I don't see any problems in dotnet/maui here, but let us know, thanks!

@samhouts samhouts changed the title [regression/8.0] Android app crashes with an ANR on .NET 8 preview 6 [regression/8.0.0] Android app crashes with an ANR on .NET 8 preview 6 Sep 18, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
external i/regression This issue described a confirmed regression on a currently supported version partner/android Issues for the Android SDK platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants