question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

zip: doOnTerminate is not called on some observables

See original GitHub issue
    @Test
    public void test() {
        Observable.zip(
                Observable.just("1")
                        .doOnTerminate(() -> System.out.println("TERMINATE 1")),
                Observable.just("2")
                        .delay(1, TimeUnit.SECONDS)
                        .doOnTerminate(() -> System.out.println("TERMINATE 2")),
                (result1, result2) -> null)
                .doOnTerminate(() -> System.out.println("TERMINATE"))
                .toBlocking()
                .single();
    }

Output:

TERMINATE 1
TERMINATE

Expected output:

TERMINATE 1
TERMINATE 2
TERMINATE

Or maybe my thinking is wrong?

Context of the problem: I use Hystrix observable commands in zip:

Observable.zip(
  new MyHystrixObservableCommand(arg1).toObservable(),
  new MyHystrixObservableCommand(arg2).toObservable(),
  (result1, result2) -> null)
.toBlocking()
.single()

and hystrix command semaphore release happens in doOnTerminate. One of them is not called and semaphore is not released.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
akarnokdcommented, May 22, 2016

With collections over time, you can’t know you are just before completion. The zip operator behaves correctly and you need a different operator, doOnTerminate+doOnUnsubscribe or using, to handle completion and unsubscription case together.

1reaction
abersnazecommented, May 21, 2016

DoOnTerminate won’t be called if the observable is unsubscribed before the onCompleted/onError. Use doOnUnsubscribe if you need to always get a call back.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - observeOn() impacts doOnTerminate() invocation
I think it is because of where the doOnTerminate should be called. In first case it is called on the new thread. So...
Read more >
Observable (RxJava Javadoc 3.1.5) - ReactiveX
Runs the current Observable to a terminal event, ignoring any values and rethrowing any exception. Subscribes to the source and calls the given...
Read more >
Observable (RxJava Javadoc 1.2.1)
Registers an Action0 to be called when this Observable invokes either ... Scheduler: doOnTerminate does not operate by default on a particular Scheduler...
Read more >
Observable (RxJava Javadoc 2.0.6)
Registers an Action to be called when this ObservableSource invokes either ... Returns an Observable that emits no items to the Observer and...
Read more >
30 RxJava - Operators - 3 ways to Zip Observables - YouTube
This video shows how to use Zip Operator to zip multiple operators together, which gives you the zipper function to work with all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found