pwittchen / ReactiveNetwork

Android library listening network connection state and Internet connectivity with RxJava Observables
http://pwittchen.github.io/ReactiveNetwork/docs/RxJava2.x/
Apache License 2.0
2.53k stars 276 forks source link

Rare DeadSystemException when device (AndroidTV) goes to sleep #387

Open stari4ek opened 4 years ago

stari4ek commented 4 years ago

Describe the bug I'm seeing rare crashes in Crashlytics with callstack:

java.lang.RuntimeException: android.os.DeadSystemException
    at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:797)
    at com.github.pwittchen.reactivenetwork.library.rx2.Connectivity.create(Connectivity.java:65)
    at com.github.pwittchen.reactivenetwork.library.rx2.Connectivity.create(Connectivity.java:50)
    at com.github.pwittchen.reactivenetwork.library.rx2.network.observing.strategy.MarshmallowNetworkObservingStrategy$5.onLost(MarshmallowNetworkObservingStrategy.java:165)
    at android.net.ConnectivityManager$CallbackHandler.handleMessage(ConnectivityManager.java:2845)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.os.HandlerThread.run(HandlerThread.java:61)

Most probably device is going to sleep or power off. And there is network notification dispatched while VM is dying.

Expected behavior It would be nice to catch those errors and route with onError

Device:

implementation 'com.github.pwittchen:reactivenetwork-rx2:3.0.6'
pwittchen commented 4 years ago

Hi @stari4ek,

Thanks for reporting this. According to the logs, it may be related to ConnectivityManager.getActiveNetworkInfo() method from Android API, which could throw DeadSystemException. I haven't seen that error before. Maybe catching this error while getting activeNetworkInfo will solve this problem. I'll have a look on that.

Regards, Piotr

stari4ek commented 4 years ago

java.lang.RuntimeException: Unable to stop service by.stari4ek.iptv4atv.tvinput.service.IptvTvInputService@4b1810b: java.lang.RuntimeException: android.os.DeadSystemException at android.app.ActivityThread.handleStopService(ActivityThread.java:3587) at android.app.ActivityThread.-wrap26(ActivityThread.java:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1703) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.RuntimeException: android.os.DeadSystemException at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1438) at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:639) at com.github.karczews.rxbroadcastreceiver.RxBroadcastReceiver$ReceiverDisposable.dispose(RxBroadcastReceiver.java:71) at io.reactivex.internal.disposables.DisposableHelper.dispose(DisposableHelper.java:124)

    ... bunch of own Rx operators

at by.stari4ek.iptv4atv.tvinput.service.IptvTvInputService.onDestroy(IptvTvInputService.java:37)
at android.app.ActivityThread.handleStopService(ActivityThread.java:3569)
pwittchen commented 4 years ago

Error from the last log looks like it's caused by another library, but general problem is probably the same.

stari4ek commented 4 years ago

ah. ouch. you're right. Sorry for that