-
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
Get RxCachedThreadScheduler-n when calling Disposable.dispose() #4863
Comments
I've add timeout setting to new OkHttpClient.Builder()
.addInterceptor(new HttpLoggingInterceptor().setLevel(debugLevel))
.addNetworkInterceptor(new StethoInterceptor())
.connectTimeout(ApiService.HTTP_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(ApiService.HTTP_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(ApiService.HTTP_TIMEOUT, TimeUnit.SECONDS)
.build(); |
Maybe your thread is in an interrupted state when you subscribe. |
How do I fix that? Or how can I cancel a api call subscription in 2.x? |
|
OK, one more question here, is my migration code from 1.x to 2.x correct? I'd like to make sure that there is only one api call at a time. if (mSubscriptionLoadMe != null && !mSubscriptionLoadMe.isDisposed())
mSubscriptionLoadMe.dispose();
mSubscriptionLoadMe = UserApi.getUserInfo(this, userId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableObserver<String>() {
onNext();
onCompleted();
onError();
}); |
Yes, the patterns remained largely the same. |
Got it, thanks for your help. |
I'm getting **_FATAL EXCEPTION: RxCachedThreadScheduler-1 when running above code. Anyone could point me to what is wrong there? EDIT |
@michaldrabik What's your full exception stack trace? |
@enginebai Pasted here: http://pastebin.com/GHjJWtiS When I remove |
This is not work for me too, I wrote a simple test app for RxJava2 and next code causes application to crash:
I start simple async task in
I expect to see my error log, but application simply crashes. |
@don11995 If you don't care about such exceptions then you can suppress them via: RxJavaPlugins.setErrorHandler(Functions.<Throwable>emptyConsumer()); |
@akarnokd , thank You, Your solution works, but what about if I want to handle this error in subscriber?
|
Such errors happen after the lifecycle of Subscribers and you can't handle them there. Cancelling a Subscriber is an indication that you no longer want to receive any events. |
That signal should be used to suppress the errors instead of conflating them with fundamentally underliverable ones (exception during onError, after onComplete, etc.). Sending the two different types of exceptions to a single callback means that you can neither crash the app to indicate a programming problem because it might just be someone that unsubscribed but you also cannot simple ignore all errors to the plugin because it might be a programming problem. |
Closing via #5075 for now. Let us know if 2.0.6 fixes this for you (tomorrow). |
@akarnokd 2.0.6 still doesn't resolve this issue for me. I just disposed an okhttp call but instead of unsubscribing normally, it just crashed. Here is the crash log.
|
@crazyhitty looks like you have an Observable.create(emitter -> {
// ...
try {
responsebody.string();
} catch (InterruptedException ex) {
if (!emitter.isDisposed()) {
emitter.onError(ex);
return;
}
}
}) |
@akarnokd You are a genius mate, thanks for the such an easy solution 👍 |
@crazyhitty since version 2.1.1
|
Requirement
I migrate from 1.x to 2.x, replace
Subscription
toDisposable
, and I'd like to cancel the subscription before a new subscription starts. But I gotRxCachedThreadScheduler-n
when callingDisposable.dispose()
. I've check #4807 and found that it may timeout problem, but I'm sure that my api is pretty fast and won't be timeout at all. How can I resolve this problem??Exception
Old 1.x Code
New 2.x Code
The text was updated successfully, but these errors were encountered: