onError throws Exception after Flowable has been unsubscribed
See original GitHub issueWe 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:
- Created 7 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Sorry, mixed up the two versions. Otherwise, it is straightforward: you have to specify a callback
Action1
/Consumer
: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?