Skip to content
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

OnErrorNotImplementedException disrupts Subject event delivery #1685

Closed
vadims opened this issue Sep 12, 2014 · 7 comments
Closed

OnErrorNotImplementedException disrupts Subject event delivery #1685

vadims opened this issue Sep 12, 2014 · 7 comments
Labels
Milestone

Comments

@vadims
Copy link
Contributor

vadims commented Sep 12, 2014

No description provided.

@vadims
Copy link
Contributor Author

vadims commented Sep 12, 2014

The following example hangs

    ReplaySubject<Object> subject = ReplaySubject.create();

    Observable.error(new RuntimeException("oops"))
        .materialize()
        .delay(1, TimeUnit.SECONDS)
        .dematerialize()
        .subscribe(subject);

    subject.subscribe();
    subject.materialize().toBlocking().first();

    System.out.println("Done");

where as

    ReplaySubject<Object> subject = ReplaySubject.create();

    Observable.error(new RuntimeException("oops"))
        .materialize()
        .delay(1, TimeUnit.SECONDS)
        .dematerialize()
        .subscribe(subject);

    subject.subscribe(n -> {}, e -> {});
    subject.materialize().toBlocking().first();

    System.out.println("Done");

does not.

@akarnokd
Copy link
Member

The plain subscribe() has an onError handler which throws an OnErrorNotImplementedException and disrupts the event delivery inside the PublishSubject.

@vadims
Copy link
Contributor Author

vadims commented Sep 26, 2014

Is that by design?

@vadims vadims changed the title Multicast/PublishSubject does not emit a terminal notification to all subscribers OnErrorNotImplementedException disrupts Subject event delivery Sep 30, 2014
@vadims
Copy link
Contributor Author

vadims commented Oct 2, 2014

@benjchristensen?

We're trying to see if we need to stop using subscribe() without an onError handler due to this behavior even when we don't need to handle the error notification.

@benjchristensen
Copy link
Member

Yes, it is by design that if an error handler is not provided, but an error occurs it will throw OnErrorNotImplementedException. We never swallow errors automatically.

If you want to swallow an error prior to the subscribe you can do something like this:

stream.onErrorResumeNext(t -> Observable.empty()).subscribe();

The subscribe overloads that don't take an error handler assume you are handling the error cases in the stream, or that errors "won't happen".

@benjchristensen
Copy link
Member

The hang may be that you're not seeing the OnErrorNotImplementedException be thrown due to the scheduling happening on delay: #1682

I haven't confirmed, but you should definitely see an exception be thrown somewhere.

@benjchristensen benjchristensen added this to the 1.0 milestone Oct 7, 2014
@benjchristensen
Copy link
Member

This one was kind of tricky ... I have to catch the error and wait until all subscribers receive the onError and then allow it to be thrown so that all subscribers are released.

Great bug. Thanks for reporting this.

benjchristensen added a commit to benjchristensen/RxJava that referenced this issue Oct 10, 2014
Fixes ReactiveX#1685 by delaying errors that are caught until after all subscribers have a chance to receive the event.

Note that this has a lot of code duplication to handle this across the Subject implementations. It may be worth abstracting this logic ... but right now I'm just doing what makes sense to fix this as the Subject abstractions are non-trivial.
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

3 participants