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

Connectivity NETWORK_CAPABILITIES_CHANGED causing SIGSEGV Segfault? #25446

Closed
RobbiewOnline opened this issue Oct 22, 2024 · 14 comments
Closed
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/android 🤖 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working

Comments

@RobbiewOnline
Copy link

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.

Image

Image

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

@PureWeen
Copy link
Member

@jonathanpeppers does this ring any bells?

@PureWeen PureWeen added platform/android 🤖 area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info labels Oct 22, 2024
@jonathanpeppers
Copy link
Member

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.

@jonathanpeppers jonathanpeppers added the s/needs-info Issue needs more info from the author label Oct 22, 2024
@dotnet-policy-service dotnet-policy-service bot added the s/no-recent-activity Issue has had no recent activity label Oct 28, 2024
@kellyethridge
Copy link

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.

@dotnet-policy-service dotnet-policy-service bot 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 Oct 29, 2024
RobbiewOnline added a commit to RobbiewOnline/MauiAppWindowTest that referenced this issue Oct 29, 2024
@RobbiewOnline
Copy link
Author

@PureWeen in reply to your questions...

Can you make a quick sample using Connectivity.ConnectivityChanged that 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.

@Zhanglirong-Winnie Zhanglirong-Winnie added s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version labels Nov 13, 2024
@Zhanglirong-Winnie
Copy link

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.

@RobbiewOnline
Copy link
Author

RobbiewOnline commented Nov 18, 2024

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.

@dotnet-policy-service dotnet-policy-service bot removed the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Nov 18, 2024
@RobbiewOnline
Copy link
Author

I note the s/try-latest-version tag has been removed, does this mean it's not expected to be fixed?

@mattleibow
Copy link
Member

Hmm, that was the bot... Not sure if it was supposed to do that.

@mattleibow mattleibow added s/try-latest-version Please try to reproduce the potential issue on the latest public version and removed s/needs-attention Issue has more information and needs another look labels Nov 18, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Nov 18, 2024
@RobbiewOnline
Copy link
Author

Hmm, that was the bot... Not sure if it was supposed to do that.

Not supposed to add or remove the tag? 🤣

@dotnet-policy-service dotnet-policy-service bot removed the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Nov 18, 2024
@PureWeen
Copy link
Member

Yea, I think the bot just removes it if you add a comment.

@PureWeen PureWeen added the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Nov 18, 2024
Copy link
Contributor

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.

@vchelaru
Copy link

vchelaru commented Nov 25, 2024

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.

Image

@drewrobey
Copy link

drewrobey commented Nov 28, 2024

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.

@drewrobey
Copy link

This isn't complete; bad bot.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/android 🤖 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants