Skip to content

Thread running otherSingleSource of a timeout is interrupted before running #5169

@janbols

Description

@janbols

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 :-).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions