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

Drain applies mappers without scheduling. #5990

Closed
AlecKazakova opened this issue May 2, 2018 · 1 comment
Closed

Drain applies mappers without scheduling. #5990

AlecKazakova opened this issue May 2, 2018 · 1 comment
Milestone

Comments

@AlecKazakova
Copy link

Here is the test case I've created

val testThread = Thread.currentThread();

rx.Observable.fromCallable { 10 }
        .toV2()
        .switchMap { original -> BehaviorSubject.createDefault(2)
            .observeOn(Schedulers.io())
            .map { multiplier ->
              if (Thread.currentThread() == testThread) throw AssertionError()
              original * multiplier
            }
        }
        .subscribe { throw IllegalStateException("nice") }

Thread.sleep(1000)

This hits the assertion error as SwitchMapObserver polls the inner query inside its drain method, running the poll method on MapObserver which ends up running on the thread the switchmap was subscribed to on (i think?).

I dont think the interop part is necessary to reproduce this bug, but was the consistent way I was able to get the drain method to poll the inner query as fromCallable emits a completion after the relay has emitted but before the mapper has received the event.

@akarnokd akarnokd added this to the 2.2 milestone May 2, 2018
@akarnokd
Copy link
Member

akarnokd commented May 2, 2018

Thanks for reporting. This is a bug in the fusion code of switchMap: it should report itself as a boundary just like flatMap to prevent this type of execution. I'll post a fix shortly. Until then you can apply hide() after map to prevent the fusion.

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

No branches or pull requests

2 participants