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

2.x: refCount doesn't reset its source if one of its subscribers cancels immediately #6296

Closed
akarnokd opened this issue Nov 8, 2018 · 5 comments · Fixed by #6297
Closed

Comments

@akarnokd
Copy link
Member

akarnokd commented Nov 8, 2018

The following tests fail because the cancel/dispose from the downstream comes before the actual connection is established which leaves the connectable source in a disposed state, refusing to take in new subscribers/observers:

@Test
public void test() {
    BehaviorSubject<Integer> subject = BehaviorSubject.create();

    Observable<Integer> observable = subject
            .replay(1)
            .refCount();

    observable.takeUntil(Observable.just(1)).test();

    subject.onNext(2);

    observable.take(1).test().assertResult(2);
}


@Test
public void test2() {
    BehaviorProcessor<Integer> processor = BehaviorProcessor.create();

    Flowable<Integer> flowable = processor
            .replay(1)
            .refCount();

    // This line causes the test to fail.
    flowable.takeUntil(Flowable.just(1)).test();

    processor.onNext(2);

    flowable.take(1).test().assertResult(2);
}
@akarnokd akarnokd added this to the 2.2 backlog milestone Nov 8, 2018
@davidmoten
Copy link
Collaborator

Thanks for letting us know. Was this discovery prompted by a report or a flash of realization?

@joshallenit
Copy link

@davidmoten This was a bug we found during development. Our actual use case was more complicated but this is what it simplified to.
@akarnokd Thanks for the quick response!

@akarnokd
Copy link
Member Author

akarnokd commented Nov 9, 2018

@artem-zinnatullin
Copy link
Contributor

+1 to @davidmoten 's comment, this is how open source projects should tackle bugs

👍 @akarnokd

@akarnokd
Copy link
Member Author

akarnokd commented Nov 9, 2018

Fix posted in #6297.

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

Successfully merging a pull request may close this issue.

4 participants