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

Avoiding OperatorObserveOn from calling subscriber.onNext(..) after unsu... #1409

Merged
merged 1 commit into from
Jul 7, 2014

Conversation

dpsm
Copy link
Contributor

@dpsm dpsm commented Jul 4, 2014

...bscribe().

The OperatorObserveOn operator uses a scheduler to cancel subscriptions as well
as to deliver the objects passing through it's onNext(..) in the right context.

Calling unsubscribe will schedule the actual unsubscription while not making sure
that the child subscriber will no longer receive calls to onNext(..) after
unsubscribe() returns.

This fix makes sure that after unsubscribe() returns no more onNext(..) calls will be
made on the child subscribers.

Signed-off-by: David Marques dpsmarques@gmail.com

@cloudbees-pull-request-builder

RxJava-pull-requests #1360 SUCCESS
This pull request looks good

@@ -136,7 +136,22 @@ private void pollQueue() {
if (v == null) {
break;
}
on.accept(observer, v);

switch (on.kind(v)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind switch adds about 20% overhead to the value delivery. Use on.isError and on.isCompleted instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akarnokd is there an on.IsNext() ? I need that or i'd have to assume that not being error or completed is next?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we use !isError() && !isCompleted(), but in this case, you'd only let an onError event through regardless of the scheduledUnsubscribe status. So:

if (on.isError(v) || !scheduledUnsubscribe.isUnsubscribed()) {
on.accept(observer, v);
}

@akarnokd
Copy link
Member

akarnokd commented Jul 4, 2014

What to change:

L56:
Subscriber s = new ObserveOnSubscriber(scheduler, child);
child.add(s);
return s;

L75: delete line

L79:
subscriber.add(recursiveScheduler);

This way, if an unsubscribe call comes from the child, it will stop the worker immediately, but upstream calls are scheduled. Beause the worker is stopped before the ObserveOnSubscriber.unsubscribe() is called, the scheduling of the worker unsubscription will not succeed.

@cloudbees-pull-request-builder

RxJava-pull-requests #1362 SUCCESS
This pull request looks good

@akarnokd
Copy link
Member

akarnokd commented Jul 4, 2014

This looks okay.

@dpsm
Copy link
Contributor Author

dpsm commented Jul 4, 2014

@akarnokd thanks for the help with this fix.

@dpsm
Copy link
Contributor Author

dpsm commented Jul 7, 2014

Adding @benjchristensen

@benjchristensen
Copy link
Member

Looks good to me. Merging and releasing soon.

@benjchristensen
Copy link
Member

Actually ... is it possible for you to re-submit this without the round-about merges along the way?

It would be less confusing to anyone looking at the history in the future. And if possible, avoid touching whitespace.

@dpsm
Copy link
Contributor Author

dpsm commented Jul 7, 2014

@benjchristensen you mean squash the commits into one?

@benjchristensen
Copy link
Member

Yes please. And if possible, revert the lines that touched whitespace and aren't involved in the fix.

…nsubscribe().

The OperatorObserveOn operator uses a scheduler to cancel subscriptions as well
as to deliver the objects passing through it's onNext(..) in the right context.

Calling unsubscribe will schedule the actual unsubscription while not making sure
that the child subscriber will no longer receive calls to onNext(..) after
unsubscribe() returns.

This fix makes sure that after unsubscribe() returns no more onNext(..) calls will be
made on the child subscribers.

Signed-off-by: David Marques <dpsmarques@gmail.com>
@dpsm
Copy link
Contributor Author

dpsm commented Jul 7, 2014

@benjchristensen done! :)

@cloudbees-pull-request-builder

RxJava-pull-requests #1366 SUCCESS
This pull request looks good

@benjchristensen
Copy link
Member

Thanks!

benjchristensen added a commit that referenced this pull request Jul 7, 2014
Avoiding OperatorObserveOn from calling subscriber.onNext(..) after unsu...
@benjchristensen benjchristensen merged commit 69b6102 into ReactiveX:master Jul 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants