microsoft / appcenter-sdk-android

Development repository for the App Center SDK for Android
Other
274 stars 135 forks source link

SDK crashes if the underlying Android call throws an exception (NetworkStateHelper.isAnyNetworkConnected) #1679

Closed mszerling-ynd closed 7 months ago

mszerling-ynd commented 1 year ago

Description

The SDK crashes if the underlying Android call throws an exception.

Repro Steps

We just observed the crash occurring randomly on production for a small subset of users.

Details

  1. Which SDK version are you using? 5.0.0
  2. Which OS version did you experience the issue on? Android 7.1.2
  3. What device version did you see this error on? Were you using an emulator or a physical device? Pax A920

crashlog:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.NetworkInfo$State.name()' on a null object reference
       at android.os.Parcel.readException(Parcel.java:1698)
       at android.os.Parcel.readException(Parcel.java:1645)
       at android.net.IConnectivityManager$Stub$Proxy.getNetworkInfoForUid(IConnectivityManager.java:1270)
       at android.net.ConnectivityManager.getNetworkInfoForUid(ConnectivityManager.java:935)
       at android.net.ConnectivityManager.getNetworkInfo(ConnectivityManager.java:929)
       at com.microsoft.appcenter.utils.NetworkStateHelper.isAnyNetworkConnected(NetworkStateHelper.java:146)
       at com.microsoft.appcenter.utils.NetworkStateHelper.isNetworkConnected(NetworkStateHelper.java:132)
       at com.microsoft.appcenter.http.HttpClientNetworkStateHandler.callAsync(HttpClientNetworkStateHandler.java:48)
       at com.microsoft.appcenter.http.HttpClientCallDecorator.run(HttpClientCallDecorator.java:54)
       at com.microsoft.appcenter.http.HttpClientRetryer.callAsync(HttpClientRetryer.java:73)
       at com.microsoft.appcenter.ingestion.AbstractAppCenterIngestion.getServiceCall(AbstractAppCenterIngestion.java:81)
       at com.microsoft.appcenter.ingestion.AppCenterIngestion.sendAsync(AppCenterIngestion.java:74)
       at com.microsoft.appcenter.channel.DefaultChannel.sendLogs(DefaultChannel.java:517)
       at com.microsoft.appcenter.channel.DefaultChannel.triggerIngestion(DefaultChannel.java:500)
       at com.microsoft.appcenter.channel.DefaultChannel.access$400(DefaultChannel.java:50)
       at com.microsoft.appcenter.channel.DefaultChannel$GroupState$1.run(DefaultChannel.java:890)
       at android.os.Handler.handleCallback(Handler.java:751)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:154)
       at android.os.HandlerThread.run(HandlerThread.java:61)
aleksandr-dorofeev commented 1 year ago

Hello @mszerling-ynd Could you elaborate more on the repro steps? Also could you share the verbose logs(documentation)?

mszerling-ynd commented 1 year ago

Hi,

as I already mentioned there are no reproduction steps we are aware of, the issue occurs randomly for a small subset of our customers on production. We only know about it because of crash reports.

Regarding enabling verbose logs that's not sth that we are willing to do for an app running on production.

I'm sorry I cannot provide more insights but I guess the stacktrace is pretty self explaining:

Obviously crashing system calls are problematic to deal with, on the other hand those calls are only used by Appcenter SDK, and if it wasn't integrated with the app at all there would be no crashes.

aleksandr-dorofeev commented 1 year ago

@mszerling-ynd I apologize for the misunderstanding with the reproduction of the error and with the situation with the logs. We are filed bug on our internal dashboard. Will back to you once get results.

DmitriyKirakosyan commented 1 year ago

Hi @mszerling-ynd , this looks like a bug of a specific version of android on a specific device. The docs doesn't mention that the method can throw, so I don't feel it is a good idea to wrap the call in try-catch. I checked the source code of the ConnectivityManager.java and related files, but couldn't find any place where it can throw an exception. Probably there is used some specific version of the service.

@mszerling-ynd , did you try to find anything similar on the internet? Having some references would help us to understand the problem better.

mszerling-ynd commented 1 year ago

Hi,

did you try to find anything similar on the internet? Having some references would help us to understand the problem better.

Unfortunately not. The affected device is a quite specific device (smart POS) not even a regular phone.

best

DmitriyKirakosyan commented 7 months ago

I'm going to close this issue as fixed. Please let me know if the bug reappears.