You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
E │ ----------UncaughtException throw--------- : io.reactivex.rxjava3.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | java.lang.InterruptedException
E │ at io.reactivex.rxjava3.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:372)
看来还是要仔细看文档啊!这个特性从2.0就开始了
第一句话已经很清晰了,One important design requirement for 2.x is that no Throwable errors should be swallowed。
任何错误都不应该被“吞掉”。
对于Rx来说第一个异常被抛出的时候,实际上生命周期已经结束了。
其他的Rx都会被取消,但是如果是并发的情况,几乎同时抛出异常,但是这时订阅已经dispose掉了,后面的异常实际上就发不出来了。
这个时候所有异常就会被汇聚到RxJavaPlugins.onError handler。
这个handle实际是可以被重写到的,通过RxJavaPlugins.setErrorHandler(Consumer)实现。
如果保持默认(不重写),RxJava defaults to printing the Throwable's stacktrace to the console and calls the current thread's uncaught exception handler.就是崩溃了,RxJava也是够决绝子的。
问题修复
根据文档提示,在Application里面增加下面代码
RxJavaPlugins.setErrorHandler(e -> {
if (e instanceof UndeliverableException) {
e = e.getCause();
}
if ((e instanceof IOException) || (e instanceof SocketException)) {
// fine, irrelevant network problem or API that throws on cancellation
return;
}
if (e instanceof InterruptedException) {
// fine, some blocking code was interrupted by a dispose call
return;
}
if ((e instanceof NullPointerException) || (e instanceof IllegalArgumentException)) {
// that's likely a bug in the application
Thread.currentThread().getUncaughtExceptionHandler()
.uncaughtException(Thread.currentThread(), e);
return;
}
if (e instanceof IllegalStateException) {
// that's a bug in RxJava or in a custom operator
Thread.currentThread().getUncaughtExceptionHandler()
.uncaughtException(Thread.currentThread(), e);
return;
}
Logger.w("Undeliverable exception received, not sure what to do", e);
});
程序不再异常了
--------------------------- PROCESS STARTED (25566) for package com.aaa.rxundeliverable ----------------------------
2023-07-27 15:24:19.005 25566-25566 rx-undeliverable com.aaa.rxundeliverable I ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:19.005 25566-25566 rx-undeliverable com.aaa.rxundeliverable I │ Thread: main
2023-07-27 15:24:19.005 25566-25566 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:19.005 25566-25566 rx-undeliverable com.aaa.rxundeliverable I │ Instrumentation.callApplicationOnCreate (Instrumentation.java:1192)
2023-07-27 15:24:19.005 25566-25566 rx-undeliverable com.aaa.rxundeliverable I │ App.onCreate (App.java:63)
2023-07-27 15:24:19.005 25566-25566 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:19.005 25566-25566 rx-undeliverable com.aaa.rxundeliverable I │ -------APP Create-------
2023-07-27 15:24:19.005 25566-25566 rx-undeliverable com.aaa.rxundeliverable I └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:28.208 25566-25645 rx-undeliverable com.aaa.rxundeliverable I ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:28.208 25566-25645 rx-undeliverable com.aaa.rxundeliverable I │ Thread: RxCachedThreadScheduler-1
2023-07-27 15:24:28.208 25566-25645 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:28.208 25566-25645 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity$$ExternalSyntheticLambda0.subscribe (null:4)
2023-07-27 15:24:28.209 25566-25645 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity.lambda$delayResult$4 (MainActivity.java:53)
2023-07-27 15:24:28.209 25566-25645 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:28.209 25566-25645 rx-undeliverable com.aaa.rxundeliverable I │ ready emit
2023-07-27 15:24:28.209 25566-25645 rx-undeliverable com.aaa.rxundeliverable I └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:28.209 25566-25648 rx-undeliverable com.aaa.rxundeliverable I ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:28.209 25566-25648 rx-undeliverable com.aaa.rxundeliverable I │ Thread: RxCachedThreadScheduler-4
2023-07-27 15:24:28.209 25566-25648 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:28.209 25566-25648 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity$$ExternalSyntheticLambda0.subscribe (null:4)
2023-07-27 15:24:28.209 25566-25648 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity.lambda$delayResult$4 (MainActivity.java:53)
2023-07-27 15:24:28.209 25566-25648 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:28.209 25566-25648 rx-undeliverable com.aaa.rxundeliverable I │ ready emit
2023-07-27 15:24:28.209 25566-25648 rx-undeliverable com.aaa.rxundeliverable I └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:28.209 25566-25647 rx-undeliverable com.aaa.rxundeliverable I ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:28.209 25566-25647 rx-undeliverable com.aaa.rxundeliverable I │ Thread: RxCachedThreadScheduler-3
2023-07-27 15:24:28.209 25566-25647 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:28.209 25566-25647 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity$$ExternalSyntheticLambda0.subscribe (null:4)
2023-07-27 15:24:28.209 25566-25647 rx-undeliverable com.aaaa.rxundeliverable I │ MainActivity.lambda$delayResult$4 (MainActivity.java:53)
2023-07-27 15:24:28.209 25566-25647 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:28.209 25566-25647 rx-undeliverable com.aaa.rxundeliverable I │ ready emit
2023-07-27 15:24:28.209 25566-25647 rx-undeliverable com.aaa.rxundeliverable I └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:28.209 25566-25646 rx-undeliverable com.aaa.rxundeliverable I ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:28.209 25566-25646 rx-undeliverable com.aaa.rxundeliverable I │ Thread: RxCachedThreadScheduler-2
2023-07-27 15:24:28.209 25566-25646 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:28.210 25566-25646 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity$$ExternalSyntheticLambda0.subscribe (null:4)
2023-07-27 15:24:28.210 25566-25646 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity.lambda$delayResult$4 (MainActivity.java:53)
2023-07-27 15:24:28.210 25566-25646 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:28.210 25566-25646 rx-undeliverable com.aaa.rxundeliverable I │ ready emit
2023-07-27 15:24:28.210 25566-25646 rx-undeliverable com.aaa.rxundeliverable I └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.210 25566-25645 rx-undeliverable com.aaa.rxundeliverable I ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.210 25566-25645 rx-undeliverable com.aaa.rxundeliverable I │ Thread: RxCachedThreadScheduler-1
2023-07-27 15:24:29.210 25566-25645 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.210 25566-25645 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity$$ExternalSyntheticLambda0.subscribe (null:4)
2023-07-27 15:24:29.210 25566-25645 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity.lambda$delayResult$4 (MainActivity.java:55)
2023-07-27 15:24:29.210 25566-25645 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.210 25566-25645 rx-undeliverable com.aaa.rxundeliverable I │ begin to emit
2023-07-27 15:24:29.210 25566-25645 rx-undeliverable com.aaa.rxundeliverable I └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.210 25566-25648 rx-undeliverable com.aaa.rxundeliverable I ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.210 25566-25648 rx-undeliverable com.aaa.rxundeliverable I │ Thread: RxCachedThreadScheduler-4
2023-07-27 15:24:29.210 25566-25648 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.210 25566-25648 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity$$ExternalSyntheticLambda0.subscribe (null:4)
2023-07-27 15:24:29.210 25566-25648 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity.lambda$delayResult$4 (MainActivity.java:55)
2023-07-27 15:24:29.210 25566-25648 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.210 25566-25648 rx-undeliverable com.aaa.rxundeliverable I │ begin to emit
2023-07-27 15:24:29.210 25566-25648 rx-undeliverable com.aaa.rxundeliverable I └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.211 25566-25647 rx-undeliverable com.aaa.rxundeliverable I ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.211 25566-25647 rx-undeliverable com.aaa.rxundeliverable I │ Thread: RxCachedThreadScheduler-3
2023-07-27 15:24:29.211 25566-25647 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.211 25566-25647 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity$$ExternalSyntheticLambda0.subscribe (null:4)
2023-07-27 15:24:29.211 25566-25647 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity.lambda$delayResult$4 (MainActivity.java:55)
2023-07-27 15:24:29.211 25566-25647 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.211 25566-25647 rx-undeliverable com.aaa.rxundeliverable I │ begin to emit
2023-07-27 15:24:29.211 25566-25647 rx-undeliverable com.aaa.rxundeliverable I └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.220 25566-25647 rx-undeliverable com.aaa.rxundeliverable W ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.220 25566-25647 rx-undeliverable com.aaa.rxundeliverable W │ Thread: RxCachedThreadScheduler-3
2023-07-27 15:24:29.220 25566-25647 rx-undeliverable com.aaa.rxundeliverable W ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.220 25566-25647 rx-undeliverable com.aaa.rxundeliverable W │ App$$ExternalSyntheticLambda1.accept (null:2)
2023-07-27 15:24:29.220 25566-25647 rx-undeliverable com.aaa.rxundeliverable W │ App.lambda$onCreate$1 (App.java:60)
2023-07-27 15:24:29.220 25566-25647 rx-undeliverable com.aaa.rxundeliverable W ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.220 25566-25647 rx-undeliverable com.aaa.rxundeliverable W │ Undeliverable exception received, not sure what to do
2023-07-27 15:24:29.220 25566-25647 rx-undeliverable com.aaa.rxundeliverable W └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.221 25566-25566 rx-undeliverable com.aaa.rxundeliverable I ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.221 25566-25566 rx-undeliverable com.aaa.rxundeliverable I │ Thread: main
2023-07-27 15:24:29.221 25566-25566 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.221 25566-25566 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity$$ExternalSyntheticLambda2.accept (null:4)
2023-07-27 15:24:29.221 25566-25566 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity.lambda$onCreate$1$com-aaa-rxundeliverable-MainActivity (MainActivity.java:36)
2023-07-27 15:24:29.221 25566-25566 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.221 25566-25566 rx-undeliverable com.aaa.rxundeliverable I │ on error:some logic error
2023-07-27 15:24:29.221 25566-25566 rx-undeliverable com.aaa.rxundeliverable I └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.221 25566-25648 rx-undeliverable com.aaa.rxundeliverable W ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.222 25566-25648 rx-undeliverable com.aaa.rxundeliverable W │ Thread: RxCachedThreadScheduler-4
2023-07-27 15:24:29.222 25566-25648 rx-undeliverable com.aaa.rxundeliverable W ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.223 25566-25648 rx-undeliverable com.aaa.rxundeliverable W │ App$$ExternalSyntheticLambda1.accept (null:2)
2023-07-27 15:24:29.223 25566-25648 rx-undeliverable com.aaa.rxundeliverable W │ App.lambda$onCreate$1 (App.java:60)
2023-07-27 15:24:29.223 25566-25648 rx-undeliverable com.aaa.rxundeliverable W ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.223 25566-25648 rx-undeliverable com.aaa.rxundeliverable W │ Undeliverable exception received, not sure what to do
2023-07-27 15:24:29.223 25566-25648 rx-undeliverable com.aaa.rxundeliverable W └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.223 25566-25646 rx-undeliverable com.aaa.rxundeliverable I ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable I │ Thread: RxCachedThreadScheduler-2
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity$$ExternalSyntheticLambda0.subscribe (null:4)
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable I │ MainActivity.lambda$delayResult$4 (MainActivity.java:55)
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable I ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable I │ begin to emit
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable I └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable W ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable W │ Thread: RxCachedThreadScheduler-2
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable W ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable W │ App$$ExternalSyntheticLambda1.accept (null:2)
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable W │ App.lambda$onCreate$1 (App.java:60)
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable W ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable W │ Undeliverable exception received, not sure what to do
2023-07-27 15:24:29.224 25566-25646 rx-undeliverable com.aaa.rxundeliverable W └────────────────────────────────────────────────────────────────────────────────────────────────────────────────
---------------------------- PROCESS ENDED (25566) for package com.aaa.rxundeliverable ----------------------------
起因
一个偶然的机会,我发现我的安卓app竟然崩了!
这个bug有些不寻常的点
这对追查问题就增加难度了
因为我处理Excetion的打印后面出现的UndeliverableException,而inner excetion看起来也是一样的
制造“事故”现场
这个错误以前我在项目也碰到过,但是复线率太低最后不了了之了。
这次重现出来虽然是也不是必现,但是重现率非常高,那是这次不可能放他走了
这次复现率高有这样的情况
异步高并发
这次的报错点在一个http的下载,是同时下载7张图片,7个下载队列同时开启
正常的http报错率高
由于服务的问题,我所有的http执行都是403报错,等于http层的出错率是 100%
这样就可以制造一个案发现场,看看能不能重现
先创建单个异步Single
然后再聚合4个Single对象为一个Observable对象
先看看正常执行情况
接下来就是模拟同时出错的情况了
终于重现了!
错误详细分析
先看日志部分
梳理一下整个进程
开始阶段
执行顺序分别是
Thread: RxCachedThreadScheduler-1
Thread: RxCachedThreadScheduler-3
Thread: RxCachedThreadScheduler-2
Thread: RxCachedThreadScheduler-4
emit 结果阶段
Thread: RxCachedThreadScheduler-1
Thread: RxCachedThreadScheduler-4
Thread: RxCachedThreadScheduler-3
注:
Thread: RxCachedThreadScheduler-2没有到emit阶段,还在sleep
Thread: RxCachedThreadScheduler-1 第一个抛出异常并被捕获
Thread: RxCachedThreadScheduler-4 第二个抛出异常但是未被捕获,被RxJavaPlugins.onError捕获
Thread: RxCachedThreadScheduler-2 没有抛出异常但是取消sleep的时候产生了InterruptedException,被RxJavaPlugins.onError捕获
Thread: RxCachedThreadScheduler-3 第三个抛出异常,还未被捕获(可能进程已经退出)
完成时间线图
揭开UndeliverableException面纱
从RxJava的github仓库的issue区入手比较直接
最终指向了RxJava的文档
看来还是要仔细看文档啊!这个特性从2.0就开始了
第一句话已经很清晰了,One important design requirement for 2.x is that no Throwable errors should be swallowed。
任何错误都不应该被“吞掉”。
对于Rx来说第一个异常被抛出的时候,实际上生命周期已经结束了。
其他的Rx都会被取消,但是如果是并发的情况,几乎同时抛出异常,但是这时订阅已经dispose掉了,后面的异常实际上就发不出来了。
这个时候所有异常就会被汇聚到RxJavaPlugins.onError handler。
这个handle实际是可以被重写到的,通过RxJavaPlugins.setErrorHandler(Consumer)实现。
如果保持默认(不重写),RxJava defaults to printing the Throwable's stacktrace to the console and calls the current thread's uncaught exception handler.就是崩溃了,RxJava也是够决绝子的。
问题修复
根据文档提示,在Application里面增加下面代码
程序不再异常了
看日志很清晰
1号线程 抛出异常被订阅捕获并抛出
2号、3号、4号线程的异常全部被阻塞,以Undeliverable exception 的形式被RxJavaPlugin的Error Handel处理。
完美解决,🎉
Demo地址
The text was updated successfully, but these errors were encountered: