Get RxCachedThreadScheduler-n when calling Disposable.dispose()
See original GitHub issueRequirement
I migrate from 1.x to 2.x, replace Subscription
to Disposable
, and I’d like to cancel the subscription before a new subscription starts. But I got RxCachedThreadScheduler-n
when calling Disposable.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
E/AndroidRuntime: FATAL EXCEPTION: RxCachedThreadScheduler-1
Process: com.machipopo.swag, PID: 30241
java.io.InterruptedIOException: thread interrupted
at okio.Timeout.throwIfReached(Timeout.java:145)
at okio.Okio$2.read(Okio.java:136)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
at okio.RealBufferedSource.request(RealBufferedSource.java:71)
at okio.RealBufferedSource.require(RealBufferedSource.java:64)
at okio.RealBufferedSource.readHexadecimalUnsignedLong(RealBufferedSource.java:270)
at okhttp3.internal.http.Http1xStream$ChunkedSource.readChunkSize(Http1xStream.java:441)
at okhttp3.internal.http.Http1xStream$ChunkedSource.read(Http1xStream.java:422)
at okio.RealBufferedSource.read(RealBufferedSource.java:50)
at okio.RealBufferedSource.exhausted(RealBufferedSource.java:60)
at okio.InflaterSource.refill(InflaterSource.java:101)
at okio.InflaterSource.read(InflaterSource.java:62)
at okio.GzipSource.read(GzipSource.java:80)
at okio.RealBufferedSource.request(RealBufferedSource.java:71)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:225)
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
at okhttp3.RealCall.execute(RealCall.java:57)
at com.test.api.ApiService.get(ApiService.java:145)
at com.test.UserApi$1.subscribe(UserApi.java:63)
Old 1.x Code
if (mSubscriptionLoadMe != null && !mSubscriptionLoadMe.isUnsubscribed())
mSubscriptionLoadMe.unsubscribe();
mSubscriptionLoadMe = UserApi.getUserInfo(this, userId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<String>() {
onNext();
onCompleted();
onError();
});
New 2.x Code
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();
});
Issue Analytics
- State:
- Created 7 years ago
- Comments:20 (8 by maintainers)
Top Results From Across the Web
FATAL EXCEPTION: RxCachedThreadScheduler-1 when ...
There is a combination of factors here: dispose of a stream that uses subscribeOn also disposes of the thread used.
Read more >When and how to use RxJava Disposable - Cups of Code
Both operations dispose the previously contained subscriptions, but dispose() operation assigns true to the disposed variable, which later does ...
Read more >Understanding the Basics of RxJava - Packt Hub
Disposable is a very simple interface. It has only two methods: dispose() and isDisposed() . dispose() can be used to cancel the existing ......
Read more >The curious case of RxJava Disposables A.K.A. what happens ...
I was playing around with Disposable s by calling dispose() on different reactive chains with ... You'll also find some cheat sheets there....
Read more >Implement a Dispose method - Microsoft Learn
Safe handles; Dispose() and Dispose(bool); Cascade dispose calls ... of IDisposable and IAsyncDisposable are properly disposed at the end of ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@crazyhitty looks like you have an
Observable.create()
around the okhttp blocking call. You have to check for cancellation before emitting any error if you don’t want to receive such errors:@don11995 If you don’t care about such exceptions then you can suppress them via: