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

Fix the issue that GroupBy may not call 'unsubscribe' #1967

Merged
merged 4 commits into from
Dec 17, 2014

Conversation

zsxwing
Copy link
Member

@zsxwing zsxwing commented Dec 12, 2014

No description provided.

@zsxwing
Copy link
Member Author

zsxwing commented Dec 12, 2014

Copy @akarnokd 's comment from #1959:

The onError seems to be simplistic. I'd expect an onError comes down, the whole contraption should be shut down and both main and groups be notified of the error. Such termination happens in onCompleted. In addition, since we use BufferUntilSubscriber, its client may throw in its onNext while replaying (no idea where it will go) or in the direct-mode phase (where it will bubble back to the emitItem) and again not tearing down anything. Now if the main was observed through unsafeSubscribe, we can't know if the downstream will eventually unsubscribe upwards or not. In addition, if a group's onNext throws, does it need to tear down everything at all or just that specific group just like the group's unsubscribe()?

@zsxwing
Copy link
Member Author

zsxwing commented Dec 12, 2014

Since Window emits the error to both the child and window Subscribers, I think GroupBy should also emit the error to all groups.

@zsxwing zsxwing force-pushed the fix-groupby-unsubscribe branch from 9666e56 to 272a752 Compare December 14, 2014 14:01
if (wip <= 0) {
return null;
}
if (WIP_FOR_UNSUBSCRIBE_UPDATER.compareAndSet(this, wip, wip + 1)) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this for making the group emission thread-safe with a concurrent unsubscribe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can take a look at the original discussion in #1959

unsubscribe();
}
// if we have no outstanding groups (all completed or unsubscribe) and terminated on outer
if (groups.isEmpty() && terminated == TERMINATED_WITH_COMPLETED) {
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this be an if/else? If we just unsubscribed in the previous lines I don't think we should ever go through this flow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right.

@zsxwing
Copy link
Member Author

zsxwing commented Dec 16, 2014

Updated.

@benjchristensen
Copy link
Member

I think this is now good. @akarnokd can you also review this again please? groupBy is non-trivial and it would be good for all 3 of us to agree.

@akarnokd
Copy link
Member

It is okay.

@benjchristensen
Copy link
Member

Thanks for the review.

benjchristensen added a commit that referenced this pull request Dec 17, 2014
Fix the issue that GroupBy may not call 'unsubscribe'
@benjchristensen benjchristensen merged commit 7c408f4 into ReactiveX:1.x Dec 17, 2014
@zsxwing zsxwing deleted the fix-groupby-unsubscribe branch December 18, 2014 01:48
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.

3 participants