Skip to content

Observable#first causes retryWhen to trigger retry without an exception #1791

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
alexwen opened this issue Oct 23, 2014 · 1 comment
Closed
Labels
Milestone

Comments

@alexwen
Copy link

alexwen commented Oct 23, 2014

Noticed this behavior using rx-netty as internally it does a take(1) internally:

    AtomicLong inc = new AtomicLong(0);
    Observable.OnSubscribe<Long> onSubscribe = subscriber -> {
        final long emit = inc.getAndIncrement();
        LOGGER.info("Emitting: {}", emit);
        subscriber.onNext(emit);
        subscriber.onCompleted();
    };

    LOGGER.info("DONE: {}", Observable.create(onSubscribe)
                    .retryWhen(attempt -> attempt.zipWith(Observable.range(1, 4), (n, i) -> i))
                    .toBlocking()
                    .first()
    );

The test output is:
Emitting: 0
Emitting: 1
DONE: 0

As you can see the observable is subscribed to twice. This is because take, in combination with single, causes the retryWhen producer to request another item.

alexwen pushed a commit to alexwen/RxJava that referenced this issue Oct 23, 2014
@alexwen alexwen mentioned this issue Oct 23, 2014
benjchristensen added a commit to benjchristensen/RxJava that referenced this issue Oct 23, 2014
@benjchristensen
Copy link
Member

Manually merged in #1793

Thank you @alexwen for submitting a bug report and then this fix!

@benjchristensen benjchristensen added this to the 1.0 milestone Oct 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants