patloew/RxLocation

Crashes if internet is off && app goes to background before gecode isFinished.

Closed this issue · 4 comments

If you switch off the internet and run the application, it will get the lat and long. Now quickly press home button to send the app to background.
It Crashes the app with following trace.

--------- beginning of crash 11-30 23:40:41.891 27364-27579/com.patloew.rxfitsample E/AndroidRuntime: FATAL EXCEPTION: RxCachedThreadScheduler-2 Process: com.patloew.rxfitsample, PID: 27364 java.io.IOException: Timed out waiting for response from server at android.location.Geocoder.getFromLocation(Geocoder.java:136) at com.patloew.rxlocation.Geocoding.lambda$fromLocation$1(Geocoding.java:62) at com.patloew.rxlocation.Geocoding$$Lambda$1.call(Unknown Source) at io.reactivex.internal.operators.single.SingleFromCallable.subscribeActual(SingleFromCallable.java:35) at io.reactivex.Single.subscribe(Single.java:2558) at io.reactivex.internal.operators.single.SingleFlatMapMaybe.subscribeActual(SingleFlatMapMaybe.java:41) at io.reactivex.Maybe.subscribe(Maybe.java:3540) at io.reactivex.internal.operators.maybe.MaybeToObservable.subscribeActual(MaybeToObservable.java:43) at io.reactivex.Observable.subscribe(Observable.java:10179) at io.reactivex.internal.operators.observable.ObservableSubscribeOn$1.run(ObservableSubscribeOn.java:39) at io.reactivex.Scheduler$1.run(Scheduler.java:134) at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:59) at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:51) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)

The cancellation behavior of RxJava 2 seems to be the cause of this, see this comment here. Try installing a custom global error handler via RxJavaPlugins.setOnError(), as suggested in this comment.

Did you able to solve this ? Thanks.

You should consider adding

RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
            @Override
            public void accept(@io.reactivex.annotations.NonNull Throwable throwable) throws Exception {
                Log.e(TAG, "Error", throwable);
            }
        });

with a link to this issue so that others will not have to hunt down this solution. 👍

@Jawnnypoo I've added a hint to the readme.