Skip to content
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

CompositeDisposable.clear causes java.lang.IllegalStateException: Unbalanced enter/exit #4110

Closed
casolorz opened this issue Jul 3, 2018 · 4 comments

Comments

@casolorz
Copy link

casolorz commented Jul 3, 2018

On the onStop of MyActivity I have a call to compositeDisposable.clear() and for some reason this causes the exception below under Android 7 and 8. I had asked about this before and I had understood that the latest D8 compiler fixed it but I continue getting that exception and as far as I know I have the latest D8 compiler under Android Studio 3.1.3. I'm using OkHtttp 3.10.0. Am I using the composite disposable wrong?

Caused by java.lang.IllegalStateException: Unbalanced enter/exit
	at okio.AsyncTimeout.enter(AsyncTimeout.java:73)
	at okio.AsyncTimeout$2.read(AsyncTimeout.java:235)
	at okio.RealBufferedSource.read(RealBufferedSource.java:47)
	at okhttp3.internal.http1.Http1Codec$AbstractSource.read(Http1Codec.java:363)
	at okhttp3.internal.http1.Http1Codec$ChunkedSource.read(Http1Codec.java:453)
	at okio.RealBufferedSource.read(RealBufferedSource.java:47)
	at okhttp3.internal.cache.CacheInterceptor$1.read(CacheInterceptor.java:174)
	at okhttp3.internal.Util.skipAll(Util.java:175)
	at okhttp3.internal.Util.discard(Util.java:157)
	at okhttp3.internal.cache.CacheInterceptor$1.close(CacheInterceptor.java:202)
	at okio.RealBufferedSource.close(RealBufferedSource.java:469)
	at okio.RealBufferedSource$1.close(RealBufferedSource.java:453)
	at java.io.BufferedInputStream.close(BufferedInputStream.java:472)
	at java.nio.channels.Channels$ReadableByteChannelImpl.implCloseChannel(Channels.java:255)
	at java.nio.channels.spi.AbstractInterruptibleChannel$1.interrupt(AbstractInterruptibleChannel.java:166)
	at java.lang.Thread.interrupt(Thread.java:956)
	at java.util.concurrent.FutureTask.cancel(FutureTask.java:146)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.cancel(ScheduledThreadPoolExecutor.java:258)
	at io.reactivex.internal.schedulers.ScheduledRunnable.dispose(ScheduledRunnable.java:107)
	at io.reactivex.disposables.CompositeDisposable.dispose(CompositeDisposable.java:217)
	at io.reactivex.disposables.CompositeDisposable.dispose(CompositeDisposable.java:80)
	at io.reactivex.internal.schedulers.IoScheduler$EventLoopWorker.dispose(IoScheduler.java:210)
	at io.reactivex.Scheduler$DisposeTask.dispose(Scheduler.java:464)
	at io.reactivex.internal.disposables.DisposableHelper.dispose(DisposableHelper.java:125)
	at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeOnObserver.dispose(ObservableSubscribeOn.java:74)
	at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.dispose(ObservableObserveOn.java:146)
	at io.reactivex.internal.disposables.DisposableHelper.dispose(DisposableHelper.java:125)
	at io.reactivex.observers.DisposableObserver.dispose(DisposableObserver.java:91)
	at io.reactivex.disposables.CompositeDisposable.dispose(CompositeDisposable.java:217)
	at io.reactivex.disposables.CompositeDisposable.clear(CompositeDisposable.java:183)
	at MyActivity.onStop(MyActivity.java:321)
	at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1289)
	at android.app.Activity.performStop(Activity.java:6841)
	at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3947)
	at android.app.ActivityThread.handleStopActivity(ActivityThread.java:4005)
	at android.app.ActivityThread.-wrap25(ActivityThread.java)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1561)
	at android.os.Handler.dispatchMessage(Handler.java:110)
	at android.os.Looper.loop(Looper.java:203)
	at android.app.ActivityThread.main(ActivityThread.java:6251)
	at java.lang.reflect.Method.invoke(Method.java)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)


@swankjesse
Copy link
Member

You're accidentally operating on the same Call from multiple threads which is forbidden.

Can you find a way to cancel the Call rather than closing its stream? That should fix.

@casolorz
Copy link
Author

casolorz commented Jul 4, 2018

I create the Call object on the Subscribe() of RxAndroid which runs Schedulers.io() however when I call compositeDisposable.clear() that is happening from the UI thread. But as far as I know I can't tell compositeDisposable.clear() what thread to run from. Maybe I need to submit this report to RxJava or RxAndroid rather than here?

@swankjesse
Copy link
Member

Somehow you’ve got to figure out how to get the Rx dispose to call Call.cancel() instead of what it’s currently doing.

@swankjesse
Copy link
Member

No action for us to take on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants