-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
3.x: Exceptions will be swallowed when schedulers are involved #6954
Comments
Fix that RxJava will miss exceptions in Future thrown by tasks executed by executors Signed-off-by: jiaoxiaodong <[email protected]>
Thanks for the report but there is no need for such complicated resolution. We only need to remove one |
yeah, I considered that adding RxJavaPlugins.onError()s and removing throwIfFatal()s, but it makes #748 a problem again. It seems tricky to balance this issue and #748. After all, if we passed StackOverflowError to RxJavaPlugins.onError(), RxJavaPlugins.onError() should throw it and it will be swallowed again. I think customizing the future task will completely solve #748 and this issue. JDK supports that and at least as I know Android are using that approach. And I think it is not complex as the core code is only implementing the JDK's interface. It even simplifies the schedulers implementation, as I see ; ) |
If you crash the |
as replied in #6956 : ) |
In general, exceptions should never be swallowed and should be handled somewhere, eg., catch clause or uncaught exception handlers of threads.
As to RxJava, exceptions are expected to be handled at:
and not to be magically swallowed somewhere.
This is true in most situations, but is broken when schedulers are involved. That is, the following tests will fail:
(Test 1) Exceptions from observables are swallowed:
(Test 2) Exceptions from observers are swallowed:
Sometimes these broken cases matter in certain situation or on certain platform, eg.,
The cause is clear. Internal to Scheduler implementation, RxJava only uses Future of a task submitted to Executor as a cancel-handle and never check exceptions inside the Future while any exception thrown by the submitted task will go into the Future.
But the fix is not as easy, there is no chance to check the Future for exception since RxJava pushes task result instead of pulls it.
Pulling results is the design intent of Future. When we won't, I think we should customize the FutureTask which runs the task in Executor and provides the Future function to give us a chance to handle the result(including the exception).
Actually, JDK has given us all we need to do this via ThreadPoolExecutor#newTaskFor, ScheduledThreadPoolExecutor#decorateTask, RunnableFuture, RunnableScheduledFuture, etc. And Android did something similar in its AsyncTask implementation.
I'll propose a PR that:
The text was updated successfully, but these errors were encountered: