Hello. Just wanted to warn anyone who is integrati...
# coroutines
Hello. Just wanted to warn anyone who is integrating Coroutines/Flow into an existing RxJava-based code base that
has proven, at least for me, to be quite unsafe and can even crash your app. I have several stack traces in https://github.com/Kotlin/kotlinx.coroutines/issues/2104.
👍 1
It seems that using this extension within streams that leverage
, or any operators that cause downstream cancellations where
is used in the downstream may run into race conditions where the Coroutine might get cancelled concurrently while the Rx
is still emitting, causing a
or a
I wish I had a solid and consistent repro, but unfortunately that is currently not the case. 😞
I got what I think similar case with Rx 😞 In my case I did
which then something finished and throw exception and I got
(The code contains a proper error handler - where usually was the reason for this error) So I found this issue in GitHub: https://github.com/ReactiveX/RxJava/issues/4991 with this comment:
This is by design, your Callable crashes and the downstream has disposed so the operator routes the error to the global error handler as it can’t know if the exception is relevant or not. Don’t crash into RxJava and consider using create() with emitter.tryOnError() instead.
The problem in my case the “Callable crash” was in Retrofit as the exception is:
Copy code
Caused by retrofit2.adapter.rxjava2.HttpException
HTTP 404 Client Error
So not sure if in my case I would be able to handle better as the comment suggests with
and `emitter.tryOnError()`… Anyway, it was the first time we notice this kind of Exception like this, and it was in our Alpha build (internal), so we will keep an eye and if becomes more often we will act on it.
Interesting scenario. 🤔
crasher has been fixed and will be included in the Coroutines 1.4 release 🎉 https://github.com/Kotlin/kotlinx.coroutines/pull/2333 Thanks @louiscad, @Tash, and @Vsevolod Tolstopyatov [JB] 👏
🙂 1