maui
maui copied to clipboard
Connectivity NETWORK_CAPABILITIES_CHANGED causing SIGSEGV Segfault?
Description
There's not much to go on here, except sentry.io capturing a segfault early in the application startup on numerous devices (Armor X7 Pro, Pixel 8, Honor X7, Pixel 6 Pro and others, across all Android versions.
The app is generally running okay, so it seems there's some network event causing it to be triggered which is making it hard to capture.
Steps to Reproduce
There's none of the usual sentry.io tracking for my app present, so it seems to crash early during the app lifecycle, always just after capturing a network event NETWORK_CAPABILITIES_CHANGED
I am using the MAUI Essentials, primarily the Connectivity.ConnectivityChanged event.
I don't know whether it's related, but I have also noticed previously that registering as a listener sometimes fails too on some devices, because I've witnessed crashes when registering the line marked <<<<<<
try
{
Connectivity.ConnectivityChanged += Current_ConnectivityChanged; <<<<<<
Logger.Log(_this, "PageManager - listening for ConnectivityChanged events");
}
catch (Exception e)
{
Logger.Log(_this, $"PageManager - TODO - UNABLE TO LISTEN FOR CONNECTIVITYCHANGED EVENTS reason {e.Message}");
}
The error was
Exception has occurred: CLR/Java.Lang.SecurityException
An unhandled exception of type 'Java.Lang.SecurityException' occurred in Mono.Android.Runtime.dll: 'com.devology.myteamsafe.app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception Android.OS.RemoteException : Remote stack trace:
at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:16580)
at android.app.IActivityManager$Stub.onTransact$registerReceiverWithFeature$(IActivityManager.java:11530)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2928)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3195)
at android.os.Binder.execTransactInternal(Binder.java:1375)
<Cannot evaluate the exception stack trace>
As far as I know essentials should be doing this behind the scenes anyway? For example in the obj folder I do see manifests with
<permission android:name="com.devology.myteamsafe.app.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION" android:protectionLevel="signature" />
<uses-permission android:name="com.devology.myteamsafe.app.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION" />
Like I say, I'm not sure whether that's related or not to the crashes.
Link to public reproduction project repository
No response
Version with bug
9.0.0-rc.2.24503.2
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
No response
Affected platforms
Android
Affected platform versions
Armor X7 Pro, Pixel 8, Honor X7, Pixel 6 Pro and others, across all Android versions.
Did you find any workaround?
None - its a segfault that kills the app
Relevant log output
No response
@jonathanpeppers does this ring any bells?
It looks to me like Java (Android OS) is throwing this exception:
An unhandled exception of type 'Java.Lang.SecurityException' occurred in Mono.Android.Runtime.dll: 'com.devology.myteamsafe.app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts'
Can you make a quick sample using Connectivity.ConnectivityChanged that shows how to cause this? It would also be helpful to know if there is a specific Android OS version this happens on.
It's possible something needs to be changed in MAUI essentials here, but I'm not sure we have enough info to know yet.
I'm also experiencing the Segfault error as recorded by Sentry. However, I'm not using the Connectivity.ConnectivityChanged event, so I'm not sure how relevant the event is to the error. Also, I'm on .NET 8 MAUI, not 9rc.
@PureWeen in reply to your questions...
Can you make a quick sample using
Connectivity.ConnectivityChangedthat shows how to cause this?
I've added it to my test project that I created to find out why Application.Current.Windows would reset to an empty list. It simply registers and listens to the connectivity event, with a binding to overlay a panel to indicate when there's no internet.
https://github.com/RobbiewOnline/MauiAppWindowTest
I've run it on a simulator in release mode and toggled wifi without issue, so I'm not sure yet whether I need to put it through a Google Play approval (so it's tested on more devices).
Judging by Sentry it crashes, but it's not all the time.
It would also be helpful to know if there is a specific Android OS version this happens on.
As per Sentry for my Beta application...
Armor X7 Pro, Pixel 8, Honor X7, Pixel 6 Pro and others, across all Android versions.
This issue has been verified using Visual Studio 17.12 Preview 5(9.0.0-rc.2.24503.2). Not repro this issue on android emulator(Pixel 8 & Pixel 6 Pro ) and Android device(Google & SM) platform. Debugging was successful, no Exception was detected and no crash.
Hi @RobbiewOnline. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.
You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.
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.
Okay, will do - I will schedule this for Wednesday (to pull in DotNet 9 official) and then hopefully release to Google Play.
Sentry does show that it has since regressed (it's come back in the last version deployed), so it's still an issue in DotNet 9 RC2, hopefully fixed in DotNet 9 released yesterday.
Kind Regards,
Rob.
I note the s/try-latest-version tag has been removed, does this mean it's not expected to be fixed?
Hmm, that was the bot... Not sure if it was supposed to do that.
Hmm, that was the bot... Not sure if it was supposed to do that.
Not supposed to add or remove the tag? 🤣
Yea, I think the bot just removes it if you add a comment.
Hi @RobbiewOnline. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.
You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.
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.
We've been seeing this a lot as well in our production app. IT happens on Android 15, 14, 13, 12, 11. It doesn't seem to be related to a particular version.
We're getting this same error on both .NET 8 and .NET 9. Only occurs on Release builds we've put into Google Play Console for test builds.
As per the OP I'm also using Sentry, the crash report doesn't give much:
SIGSEGV: Segfault
Network Event
data: {"upload_bandwidth":37228,"action":"NETWORK_CAPABILITIES_CHANGED","vpn_active":false,"signal_strength":-76,"network_type":"wifi","download_bandwidth":29562}
The app stays up for about 10 to 15 seconds, then crashes with the segfault. Sounds like some kind of polling routine checking for network connectivity, despite the fact our app doesn't use any network features whatsoever.
EDIT: The same sort of segfault also gets triggered with a different error, triggered by the BATTERY_CHANGED event:
SIGSEGV: Segfault
data: {"level":84.0,"charging":true,"action":"BATTERY_CHANGED"}
It seems something in Maui is sensitive to certain OS level events being raised.
This isn't complete; bad bot.