Skip to content

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

@alexwen

Description

@alexwen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions