-
Notifications
You must be signed in to change notification settings - Fork 1.9k
ObservableSource.asFlow() extension should at least surround sendBlocking() call with try/catch block #2299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This issue would also exist in kotlinx.coroutines/reactive/kotlinx-coroutines-rx3/src/RxConvert.kt Lines 78 to 90 in 1b34e1c
These implementations don't adhere to the kotlinx.coroutines/kotlinx-coroutines-core/common/src/flow/Builders.kt Lines 302 to 310 in 1b34e1c
If only to avoid repeating code with fun <E> SendChannel<E>.safeSendBlocking/sendBlockingCatching(value: E) {
return runCatching { sendBlocking(value) }
}
// OR
fun <E> SendChannel<E>.safeSendBlocking/sendBlockingCatching(value: E) {
return try {
sendBlocking(value)
} catch (ex: ClosedSendChannelException) { // or other exceptions
// ...
}
} |
I work out of an Android code base that is mostly Rx-based. However, we have started writing new code using Coroutines. The
kotlinx-coroutines-rx2
library is crucial for interfacing between the two libraries. However,ObservableSource.asFlow()
has proven to be dangerous and has introduced crashes for us in production.Please see #2104. I have shared several stack traces in that issue we have been seeing. The root cause seems to correspond with #974. However, it seems that effort is going to take some careful redesign. In the meantime, can we consider wrapping the call to
sendBlocking()
with atry/catch
block? I'm thinking thecatch
block can specifically catchCancellationException
or the appropriate subtypes, e.g.,JobCancellationException
andChildCancelledException
to avoid catching allExceptions
.The text was updated successfully, but these errors were encountered: