Skip to content

ReplaySubject and buffer with debounce not emitting values after first subscription #6608

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

Closed
riclage opened this issue Aug 2, 2019 · 3 comments · Fixed by #6609
Closed
Milestone

Comments

@riclage
Copy link

riclage commented Aug 2, 2019

The issue described below started with version 2.2.10 and continues with 2.2.11. It works with 2.2.7 through 2.2.9.

I have a test where a set a ReplaySubject like so:

locationPublisher = ReplaySubject.create()
locationPublisher.onNext(mockLocation)
locationPublisher.onComplete()

locationObservable = locationPublisher.share()

Then, I subscribe twice to the observable (I'm simplifying the test case just to demonstrate the bug):

        locationObservable
            .buffer(locationObservable.debounce(5, TimeUnit.SECONDS))
            .test()
            .assertValueCount(2)


        locationObservable
            .buffer(locationObservable.debounce(5, TimeUnit.SECONDS))
            .test()
            .assertValueCount(2)

When I run the above test, it fails on the second test subscription on RxJava 2.2.10 or 2.2.11:

java.lang.AssertionError: Value counts differ; expected: 2 but was: 1 (latch = 0, values = 1, errors = 0, completions = 1)
Expected :2
Actual :1 (latch = 0, values = 1, errors = 0, completions = 1)

@akarnokd
Copy link
Member

akarnokd commented Aug 2, 2019

Hi and thanks for reporting. This is a bug in refCount affecting both 2.x and 3.x.

What happens is that when the source subject completes, it completes buffer, which then cancels the boundary source, which makes the refCount think it still has 1 subscriber active and doesn't reset the source.

The operator is a bit delicate so I have to work out the correct state transitions and not break tests...

@akarnokd
Copy link
Member

akarnokd commented Aug 5, 2019

Hi. I can't seem to reproduce this with 2.2.11. Could you check if the following test passes for you on 2.2.11?

@Test
public void upstreamTerminationTriggersAnotherCancel() throws Exception {
    ReplaySubject<Integer> rs = ReplaySubject.create();
    rs.onNext(1);
    rs.onComplete();

    Observable<Integer> shared = rs.share();

    shared
    .buffer(shared.debounce(5, TimeUnit.SECONDS))
    .test()
    .assertValueCount(2);

    shared
    .buffer(shared.debounce(5, TimeUnit.SECONDS))
    .test()
    .assertValueCount(2);
}

@riclage
Copy link
Author

riclage commented Aug 5, 2019

Yes, I just created a new project with Android Studio and added only RxJava as a new dependency and your test above.

It fails on versions 2.2.10 and 2.2.11 put passes on 2.2.9.

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.

2 participants