RxJava icon indicating copy to clipboard operation
RxJava copied to clipboard

Observable#first causes retryWhen to trigger retry without an exception

Open alexwen opened this issue 12 years ago • 1 comments

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 avatar Oct 23 '14 18:10 alexwen

Manually merged in https://github.com/ReactiveX/RxJava/pull/1793

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

benjchristensen avatar Oct 23 '14 21:10 benjchristensen