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 issues that GroupBy and Sample doesn't call 'unsubscribe' and also NPE when the key is null in GroupBy #1959

Closed
wants to merge 8 commits into from

Conversation

zsxwing
Copy link
Member

@zsxwing zsxwing commented Dec 12, 2014

Fix #1958

@zsxwing
Copy link
Member Author

zsxwing commented Dec 12, 2014

Find two more bugs:

  • GroupBy may not call unsubscribe
  • NPE if the key is null in GroupBy
    The unit tests demonstrates them.

@zsxwing
Copy link
Member Author

zsxwing commented Dec 12, 2014

Fixed them in this PR.

@zsxwing zsxwing changed the title Fix the issue that Sample doesn't call 'unsubscribe' Fix the issue that GroupBy and Sample doesn't call 'unsubscribe' and also NPE when the key is null in GroupBy Dec 12, 2014
@zsxwing zsxwing changed the title Fix the issue that GroupBy and Sample doesn't call 'unsubscribe' and also NPE when the key is null in GroupBy Fix issues that GroupBy and Sample doesn't call 'unsubscribe' and also NPE when the key is null in GroupBy Dec 12, 2014
@@ -75,6 +77,7 @@ public OperatorGroupBy(
final Func1<? super T, ? extends K> keySelector;
final Func1<? super T, ? extends R> elementSelector;
final Subscriber<? super GroupedObservable<K, R>> child;
final Subscription parentSubscription = this;
Copy link
Member

Choose a reason for hiding this comment

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

There is a self member variable which also points to this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point.

@@ -68,6 +68,7 @@ public OperatorSampleWithTime(long time, TimeUnit unit, Scheduler scheduler) {
static final AtomicReferenceFieldUpdater<SamplerSubscriber, Object> VALUE_UPDATER
= AtomicReferenceFieldUpdater.newUpdater(SamplerSubscriber.class, Object.class, "value");
public SamplerSubscriber(Subscriber<? super T> subscriber) {
super(subscriber);
Copy link
Member

Choose a reason for hiding this comment

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

This will unsubscribe the downstream. I suggest instead having child.add(sampler); after L52.

Copy link
Member

Choose a reason for hiding this comment

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

I haven't had a chance to try this code yet, but I want to make sure this doesn't break the backpressure functionality where this operator requests Long.MAX_VALUE up.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will unsubscribe the downstream. I suggest instead having child.add(sampler); after L52.

Could you elaborate? I think unsubscribe the downstream would be OK for this operator.

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't had a chance to try this code yet, but I want to make sure this doesn't break the backpressure functionality where this operator requests Long.MAX_VALUE up.

sample with time does not support backpressure as it uses time to control data flow, right?

// if we have no outstanding groups (all completed or unsubscribe) and terminated/unsubscribed on outer
if (groups.size() == 0 && (terminated == 1 || child.isUnsubscribed())) {
if (groups.isEmpty() && (terminated == 1 || child.isUnsubscribed())) {
Copy link
Member

Choose a reason for hiding this comment

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

I feel some redundancy here. Maybe it is worth reviewing the other counters and state indicators.

@zsxwing
Copy link
Member Author

zsxwing commented Dec 12, 2014

This PR contains a lot. I will split it to 3 PRs.

@zsxwing zsxwing closed this Dec 12, 2014
@zsxwing
Copy link
Member Author

zsxwing commented Dec 12, 2014

Split to #1965 #1966 #1967

@zsxwing zsxwing deleted the sample-unsubscribe branch December 15, 2014 07:00
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