karczews/RxBroadcastReceiver

DeadSystemException during dispose

Closed this issue · 3 comments

I'm seeing small amount of DeadSystemException on Android TV devices.
Most probably device is going to power off and VM is dying already when RxBroadcastReceiver is trying to dispose.

Android: 8.0.0
Android Build: 31100 OTT1.180130.001
Manufacturer: SHARP
Model: AQUOS-4KTVX17
Thread: main-2

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)

I'd expect that unregistering BroadcastReceiver should be wrapped and onError emitted (or swallowed?)

Hi, thanks for report. On a first glance it looks like everything is done properly - unregistering BroadcastReceiver during onDestroy is a normal scenario - its a pity that tv does not allow this unregistration to be performed gracefully.

As for error itself, emitting it makes not sense to me since this happens during disposal. Once subscriber calls dispose on Disaposable, it should not receive any more events. Maybe simplest solution would be wrapping dispose call in your service with try/catch ?

Yeah, it's possible solution but requires non-trivial injecting of own operators to process normal disposing flow (I'm using rxlifecycle to bind to service's lifecycle).

But I checked some standard operators and it's more common to wrap with try-catch success/next emission but not disposing one.

thank you for taking a look

You can try using version 1.0.6 that will use standard way of handling this case - it will send error to RxJavaPlugins. It will be consumed by error handler if set in RxJavaPlugins or send it to Thread's UncaughtExceptionHandler otherwise.