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

NETWORK_CAPABILITIES_CHANGED and BATTERY_CHANGED events on Android (with Maui) causing SIGSEGV Segfault #3828

Open
drewrobey opened this issue Dec 5, 2024 · 16 comments
Milestone

Comments

@drewrobey
Copy link

Package

Sentry

.NET Flavor

.NET

.NET Version

9.0

OS

Android

SDK Version

4.13.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

  1. Create .Net MAUI application in Visual Studio.
  2. Install Sentry.Maui from Nuget and setup.
  3. Build a Release version of the Android app and install on mobile phone.
  4. The app will crash within first 30 seconds of startup.

Expected Result

App should not crash.

Actual Result

As per Keren from Sentry's request I've created this issue, he's my original support message:

I'm using Sentry with .Net Maui, and I think I may have discovered a bug.

We've been receiving SEGFAULT runtime errors - apps crashing after maybe 20 seconds of startup, triggered by NETWORK_CAPABILITIES_CHANGED and BATTERY_CHANGED events. This problem has been reported by someone else to the Maui team via Github, and I've been helping to investigate the issue dotnet/maui#25446

I've discovered that the common denominator with all users having these problems is that they're using Sentry.Maui

When we remove Sentry from our builds the crashes stop. When we add Sentry back in, and remove AOT and trimming, the crashes stop. It looks like the Maui compilation linker is trimming certain methods from the Sentry plugin, which is causing the crashes, as these methods are clearly being called somewhere, possibly being called via Reflection or the like.

Perhaps it's possible to have Sentry's classes marked with directives to prevent trimming, so that they're preserved in-full during compilation?

@bitsandfoxes
Copy link
Contributor

Thanks for reaching out!
I'm not too familiar with the trimming options but I was under the impression that we add the assembly as root for the trimmer? But I can't find where this happens anymore. Maybe @jamescrosswell knows?

@drewrobey
Copy link
Author

@bitsandfoxes I'm in the UK so I'm not at my desk right now, but tomorrow I'll try and attach some screenshots of the AOT settings to illustrate what I mean a bit better.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 5, 2024
@bruno-garcia
Copy link
Member

Just a thought, not sure it'll help but does this happen on the latest preview release of the SDK? version 5

@jamescrosswell
Copy link
Collaborator

Hi @drewrobey, if you're using .NET 9 then you'll want/need to use Sentry version 5.x. Version 4.x wasn't built or tested with .NET 9.

Version 5.0.0 isn't yet available. We're hoping to have an early beta available in the couple of weeks. One of the main things that we have to do before making that release is enable the new AOT analyzers for MAUI apps and work through any/all warnings that those produce... so working through issues like this, basically.

It'd be great to get some help testing that from people who are already looking to move to .NET 9.

@drewrobey
Copy link
Author

@jamescrosswell I've only upgraded to .net 9 in this last week, and before that the same crashes were occurring on .net 8

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 5, 2024
@drewrobey
Copy link
Author

Image

Further to my comment from last night, here's a screenshot of the Visual Studio build settings that I'm referring to, namely the AOT and trimming settings - the nuclear option I've found prevents the crashes is to turn off AOT entirely.

@bruno-garcia
Copy link
Member

This helps narrow down. Thanks

@drewrobey
Copy link
Author

The email bot is saying it'll close the ticket if I don't respond, so here's a response to make sure that doesn't happen...

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 10, 2024
@bruno-garcia
Copy link
Member

are you sure it was on this ticket? we won't let it close, don't worry.

@drewrobey
Copy link
Author

@bruno-garcia Yep, it was this ticket: it's the only Sentry ticket I've opened.

@drewrobey
Copy link
Author

@bruno-garcia Just received another one of the automated emails from sentry.io, the content says:

Hope all is well with you! Just dropping in to say we haven't heard back from you about your ticket. We still want to help if you're stuck.

Since it's been a while, we'll be closing the ticket for now. But hey, don't worry! If there's anything more you need or if you want to reopen the ticket, just shoot us a message anytime.

Would it auto-close the ticket if there's no new info?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 12, 2024
@bruno-garcia
Copy link
Member

bruno-garcia commented Dec 12, 2024

@bruno-garcia Just received another one of the automated emails from sentry.io, the content says:

Hope all is well with you! Just dropping in to say we haven't heard back from you about your ticket. We still want to help if you're stuck.

Since it's been a while, we'll be closing the ticket for now. But hey, don't worry! If there's anything more you need or if you want to reopen the ticket, just shoot us a message anytime.

Would it auto-close the ticket if there's no new info?

it will not. It would take a long time and we would see this message on the ticket. The bot writes on GitHub, that email doesn't come from Sentry it's just a github notification via email. Unless this is an old email, or about another issue, I'm not sure why you would receive it.

@Mittchel
Copy link

We are experiencing the same thing on a lot of our apps at the moment. Today one of our apps actually got rejected.

Has anyone tested whether this issue occurs on the 5.0.0 alpha package?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 16, 2024
@jamescrosswell
Copy link
Collaborator

Has anyone tested whether this issue occurs on the 5.0.0 alpha package?

I haven't had time to look at this issue (or been able to reproduce it yet).

I've kind of been working on it indirectly - This PR ensures Sentry.Maui is trim compatible... once that's merged, we could put together another pre-release to see if it has any impact on this issue.

There's also one other change in the version 5.0.0 branch that relates to issues reading the network status, so that could potentially be related. Again, we could test that in the next pre-release.

Apologies for the wait on this - we're a bit short handed on the .NET SDK at the moment.

@jamescrosswell
Copy link
Collaborator

Further to my comment from last night, here's a screenshot of the Visual Studio build settings that I'm referring to, namely the AOT and trimming settings - the nuclear option I've found prevents the crashes is to turn off AOT entirely.

@drewrobey from what I can tell, AOT isn't yet supported on Android:

The tracking issues there seem to have a .NET 10.0 milestone:

In our own samples, we only enable this for ios and maccatalyst targets:

<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios' or $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">
<PublishAot>true</PublishAot>
</PropertyGroup>

@drewrobey
Copy link
Author

@jamescrosswell That's interesting.

Doing some further reading it turns out full AOT for Android does indeed not exist, but partial AOT does, which would explain why the AOT build option has been in there for Android since the Xamarin days:

Partial AOT for Startup Optimization:

    The AOT option in Visual Studio applies to startup-critical paths rather than the entire application.
    This can improve application launch times and runtime performance by precompiling certain code segments into native machine code.

Integration from Xamarin.Android:

    .NET MAUI inherits features from Xamarin.Android, which supports partial AOT for performance tuning.
    The AOT option targets specific assemblies or methods to reduce JIT overhead.

FYI there have been a couple of Maui framework Nuget updates in the last couple of days, that I'm currently experimenting with - let me see if these have any effect on this bug, as there's a lot of changes happening all of a sudden, and I need to isolate some variables to ensure I'm not sending you on a wild goose chase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: No status
Development

No branches or pull requests

5 participants