在 Android 7 上改造 2 + RxJava StackOverflowError

Retrofit 2 + RxJava StackOverflowError on Android 7

我在 Crashlytics 中看到一些与 Retrofit 2 和 RxJava 1 相关的 Android 7 错误。根本没有提及任何应用程序代码。设备尚未植根,应用程序大多未获得关注。到目前为止,在我的任何设备上都没有被复制。

堆栈跟踪如下:

Fatal Exception: java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
   at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:114)
   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)
Caused by java.lang.WhosebugError: stack size 1037KB
   at rx.exceptions.Exceptions.throwIfAny(Exceptions.java:174)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:144)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.subscriptions.CompositeSubscription.unsubscribeFromAll(CompositeSubscription.java:186)
   at rx.subscriptions.CompositeSubscription.unsubscribe(CompositeSubscription.java:175)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.subscriptions.CompositeSubscription.unsubscribeFromAll(CompositeSubscription.java:186)
   at rx.subscriptions.CompositeSubscription.unsubscribe(CompositeSubscription.java:175)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.subscriptions.CompositeSubscription.unsubscribeFromAll(CompositeSubscription.java:186)
   at rx.subscriptions.CompositeSubscription.unsubscribe(CompositeSubscription.java:175)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.subscriptions.CompositeSubscription.unsubscribeFromAll(CompositeSubscription.java:186)
   at rx.subscriptions.CompositeSubscription.unsubscribe(CompositeSubscription.java:175)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.subscriptions.CompositeSubscription.unsubscribeFromAll(CompositeSubscription.java:186)
   at rx.subscriptions.CompositeSubscription.unsubscribe(CompositeSubscription.java:175)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.subscriptions.CompositeSubscription.unsubscribeFromAll(CompositeSubscription.java:186)
   at rx.subscriptions.CompositeSubscription.unsubscribe(CompositeSubscription.java:175)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.subscriptions.CompositeSubscription.unsubscribeFromAll(CompositeSubscription.java:186)
   at rx.subscriptions.CompositeSubscription.unsubscribe(CompositeSubscription.java:175)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.subscriptions.CompositeSubscription.unsubscribeFromAll(CompositeSubscription.java:186)
   at rx.subscriptions.CompositeSubscription.unsubscribe(CompositeSubscription.java:175)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.subscriptions.CompositeSubscription.unsubscribeFromAll(CompositeSubscription.java:186)
   at rx.subscriptions.CompositeSubscription.unsubscribe(CompositeSubscription.java:175)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.subscriptions.CompositeSubscription.unsubscribeFromAll(CompositeSubscription.java:186)
   at rx.subscriptions.CompositeSubscription.unsubscribe(CompositeSubscription.java:175)
   at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:136)
   at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:125)
   at rx.Subscriber.unsubscribe(Subscriber.java:98)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:820)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:852)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:852)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:852)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:852)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:852)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:852)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:852)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:852)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:852)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:852)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.onError(OperatorMerge.java:276)
   at rx.internal.operators.OnSubscribeMap$MapSubscriber.onError(OnSubscribeMap.java:88)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.onError(OperatorMerge.java:276)
   at rx.internal.operators.OnSubscribeMap$MapSubscriber.onError(OnSubscribeMap.java:88)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
   at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:852)
   at retrofit2.adapter.rxjava.OperatorMapResponseToBodyOrError.onError(OperatorMapResponseToBodyOrError.java:52)
   at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:178)
   at rx.Subscriber.setProducer(Subscriber.java:211)
   at rx.Subscriber.setProducer(Subscriber.java:205)
   at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:152)
   at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:138)
   at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
   at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
   at rx.Observable.unsafeSubscribe(Observable.java:10256)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:248)
   at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:148)
   at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
   at rx.internal.util.ScalarSynchronousObservable$ScalarAsyncProducer.call(ScalarSynchronousObservable.java:200)
   at rx.internal.util.ScalarSynchronousObservable.call(ScalarSynchronousObservable.java:114)
   at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:107)
   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)

问题不是供应商特定的(三星、摩托罗拉、华为等)。有什么想法吗?

根据堆栈跟踪,您似乎有极其嵌套的 merge 运算符。是否有任何地方可以使用 Observables 集合并执行类似

的操作
Iterator<Observable<T>> it = collection.iterator();
Observable<?> obs = it.next();
while(it.hasNext()) obs=obs.merge(it.next()); 

或类似的东西(可能通过 .scan())?