question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onError throws Exception after Flowable has been unsubscribed

See original GitHub issue

We have recently run up against this in RxJava 2.0.x, and I would like to clarify that this is the intended behaviour.

We are creating a Flowable that connects to a remote server and first needs to resolve the host. If host cannot be resolved, the UnknownHostException is propagated via onError:

val messages = Flowable.create<SourcedMessage>({ subscriber ->
        this.subscriber = subscriber
        try{
            addr = InetAddress.getByName(host)
        }catch (e:UnknownHostException){
            subscriber.onError(e)
            return@create
        }
       .....
}

This seems to work fine (we can use an invalid hostname and the retry logic wrapping it fires just as expected), but we have seen crashes in our crashlogs, where the Android app crashes with an uncaught UnknownHostException, which we did not expect. The crash goes away as soon as we check subscriber.isCancelled before calling onError as in:

val messages = Flowable.create<SourcedMessage>({ subscriber ->
        this.subscriber = subscriber
        try{
            addr = InetAddress.getByName(host)
        }catch (e:UnknownHostException){
            if(!subscriber.isCancelled){
                    subscriber.onError(e)
            }
            return@create
        }
       .....
}

For what it matters the Flowable is further chained in a subscribeOn(Schedulers.io()).retryWhen().publish.refCount() chain that is observedOn and subscribed to on the AndroidScheduler.mainThread.

We would have expected the onError just being silently ignored after unsubscription (which occurs when the app goes into the background). Maybe #4863 and #4807 are related too.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
akarnokdcommented, Jan 9, 2017

Sorry, mixed up the two versions. Otherwise, it is straightforward: you have to specify a callback Action1/Consumer:

// 1.x
RxJavaHooks.setOnError(e -> System.out.println(e.getMessage()));

// 2.x
RxJavaPlugins.setErrorHandler(e -> System.out.println(e.getMessage()));
0reactions
PaulWoitaschekcommented, Jan 10, 2017

So with it I don’t see legitimate programming erros and without it my App crashes without legitimate programming errors?

Is it possible to somehow get the old behaviour back so my app crashes only when I made a mistake?

Read more comments on GitHub >

github_iconTop Results From Across the Web

RxJava throwing an exception or using onError - Stack Overflow
If I have a method that should throw NPE if the argument is null, should this exception be thrown by the method itself...
Read more >
RxJava 2.x | rxjava-walkthrough
Flowable Publisher that emits 0..N elements, and then completes successfully or with an error. Observable like Flowables but without a backpressure strategy.
Read more >
RxJava1 -> RxJava2 Upgrade Notes/Tips | by Ken Yee | Medium
If your observable has a delayed error from a network call, it will crash without one set, even if the observable has been...
Read more >
ReactiveX/RxJava - Gitter
In this scenario if possiblyExceptionCompletable throws an exception - both the success and failure updates occur. Exerosis. @Exerosis.
Read more >
Index (RxJava Javadoc 3.0.0-RC6) - ReactiveX
Assert that this TestObserver/TestSubscriber has not received any onError event. ... Returns the first item emitted by this Flowable , or throws ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found