Skip to content

Avoid merge operator from over requesting upstream producer #2766

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
dpsm opened this issue Feb 21, 2015 · 3 comments
Closed

Avoid merge operator from over requesting upstream producer #2766

dpsm opened this issue Feb 21, 2015 · 3 comments

Comments

@dpsm
Copy link
Contributor

dpsm commented Feb 21, 2015

The merge operator requests from upstream disregarding the amount
of requested items from downstream. This causes an issue where
it creates a produce/consume cycle that is infinite and puts
pressure on producer.

The code below illustrates the case where it loops and never emits anything to the downstream subscriber.

final AtomicInteger generated1 = new AtomicInteger();
        final TestScheduler scheduler = new TestScheduler();
        TestSubscriber<Integer> nonScalartestSubscriber = spy(new TestSubscriber<Integer>() {
            @Override
            public void onStart() {
                request(10);
            }
        });
        Observable<Integer> o1 = createInfiniteObservable(generated1)
            .flatMap(new Func1<Integer, Observable<Integer>>() {
                @Override
                public Observable<Integer> call(final Integer integer) {
                    return Observable.create(new OnSubscribe<Integer>() {
                        @Override
                        public void call(Subscriber<? super Integer> subscriber) {
                            subscriber.onNext(-integer);
                            subscriber.onCompleted();
                        }
                    });
                }
            })
            .subscribeOn(scheduler);
        o1.subscribe(nonScalartestSubscriber);
@dpsm
Copy link
Contributor Author

dpsm commented Feb 21, 2015

A pull request is available at #2765

@benjchristensen
Copy link
Member

Long discussion about this going on at #2765 ... it's nuanced.

@akarnokd
Copy link
Member

I'm closing this in favor of discussing it on PR #2928 instead.

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

3 participants