T-Spoon / Traceur

Easier RxJava2 debugging with better stacktraces
489 stars 28 forks source link

Traceur causing `StackOverflowError` on too complex `CompositeException` #4

Open mkoslacz opened 7 years ago

mkoslacz commented 7 years ago

Hi,

Recently I have encountered a problem using Traceur on Android.

In my project I sometimes got OOM errors when trying to log too complex CompositeExceptions from external components using Android Log.e method. To avoid it I strip these exceptions to have 5 original exceptions max using stripCompositeException method included in the gist I linked at the end of this issue.

In the regular setup this approach works correctly, but using Traceur, on less performant devices and older apis that have older memory management alghoritms (in my case API 17) I got uncaught StackOverflowError that crashes my app. I include the error I'm encountering in the attached test case:

07-01 12:42:09.746 2489-2489/pl.videostar E/AndroidRuntime: FATAL EXCEPTION: main
                                                            java.lang.StackOverflowError
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onSubscribe(ObservableDoOnEach.java:71)
                                                                at io.reactivex.internal.observers.BasicFuseableObserver.onSubscribe(BasicFuseableObserver.java:66)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onSubscribe(ObservableDoOnEach.java:73)
                                                                at io.reactivex.internal.observers.BasicFuseableObserver.onSubscribe(BasicFuseableObserver.java:66)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onSubscribe(ObservableDoOnEach.java:73)
                                                                at io.reactivex.internal.observers.BasicFuseableObserver.onSubscribe(BasicFuseableObserver.java:66)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onSubscribe(ObservableDoOnEach.java:73)
                                                                at io.reactivex.internal.observers.BasicFuseableObserver.onSubscribe(BasicFuseableObserver.java:66)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onSubscribe(ObservableDoOnEach.java:73)
                                                                at io.reactivex.internal.observers.BasicFuseableObserver.onSubscribe(BasicFuseableObserver.java:66)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onSubscribe(ObservableDoOnEach.java:73)
                                                                at io.reactivex.internal.observers.BasicFuseableObserver.onSubscribe(BasicFuseableObserver.java:66)
                                                                at io.reactivex.internal.operators.observable.ObservableJust.subscribeActual(ObservableJust.java:34)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at com.tspoon.traceur.ObservableOnAssemblyScalarCallable.subscribeActual(ObservableOnAssemblyScalarCallable.java:40)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at com.tspoon.traceur.ObservableOnAssembly.subscribeActual(ObservableOnAssembly.java:43)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at com.tspoon.traceur.ObservableOnAssembly.subscribeActual(ObservableOnAssembly.java:43)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at com.tspoon.traceur.ObservableOnAssembly.subscribeActual(ObservableOnAssembly.java:43)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at com.tspoon.traceur.ObservableOnAssembly.subscribeActual(ObservableOnAssembly.java:43)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at com.tspoon.traceur.ObservableOnAssembly.subscribeActual(ObservableOnAssembly.java:43)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at com.tspoon.traceur.ObservableOnAssembly.subscribeActual(ObservableOnAssembly.java:43)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at com.tspoon.traceur.ObservableOnAssembly.subscribeActual(ObservableOnAssembly.java:43)
                                                                at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                at io.reactivex.internal.operators.observable.ObservableDoOnEach.su

Although, on API 25 Traceur won't crash the app and will log the excepton correctly, but still, in such case the printed stacktrace is so huge that it fills up whole Android Logcat console and eventually breaks it withread: unexpected EOF! what also makes logging useless.

Is it possible to create some constraints in Traceur that would prevent such issues?

I have created the test case here. Let me know if you wouldn't be able to reproduce the issue.

T-Spoon commented 7 years ago

Hey!

Not in a dev environment at the moment - but there is TraceurConfig. SHOW_ONLY_FIRST - which will append only a single exception. Might be suitable for your use case (but could potentially remove a lot of useful info)

It would be better to be able to customise this behaviour more though - potentially by supplying a custom function to determine whether or not an exception should be appended to the stacktrace.

When I get a chance I'll take a look at implementing this!

5upernaut commented 7 years ago

Hi! Great library! It looks like it's not possible to set the LogLevel to SHOW_ONLY_FIRST, or did I miss something?