-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Description
Hi, I'm running io.reactivex.rxjava2:rxjava:2.0.6 .
When doing the following, the thread running the otherSingleSource has its interrupted flag set. This throws java.lang.InterruptedExceptions. Below, you can find an example:
Single.timer(3, TimeUnit.SECONDS)
.timeout(1, TimeUnit.SECONDS, Single.fromCallable { return Long.MAX_VALUE })
.blockingGet()
The thread that runs return Long.MAX_VALUE is interrupted. You can find a unit test using spock on https://gist.github.com/janbols/e97ceb349641f58895379ff562aab59b
The same effect is observed when we call timeout with an explicit scheduler. The only way I could make this working is by subscribing the otherSingleSource on another thread like the following:
Single.timer(3, TimeUnit.SECONDS)
.timeout(1, TimeUnit.SECONDS, Single.fromCallable { return Long.MAX_VALUE }).subscribeOn(io())
.blockingGet()
I tried to debug the code and I think it has something to do with the call to set.clear() inside the runnable when the timer expires in io.reactivex.internal.operators.single.SingleTimeout#subscribeActual. At that time set contains the timer disposable and by clearing it, you're also interrupting the thread that's running the task in io.reactivex.internal.schedulers.ScheduledRunnable#dispose.
Of course I could be completely wrong as well since thread scheduling isn't really my cup of tea :-).