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

chore(take): test case for error notification after limit is reached #6394

Merged
merged 1 commit into from
May 10, 2021

Conversation

backbone87
Copy link
Contributor

@backbone87 backbone87 commented May 10, 2021

Description:
provides a failing test case for an edge case of take and dependent operators as presented in #5487

Will add a fix, if a change in behavior is agreed upon.

Related issue (if exists): fixes #5487

@cartant
Copy link
Collaborator

cartant commented May 10, 2021

The behaviour reported in that issue is a bug. It's supposed to stop listening.

IMO, I would deem this a bug fix - pretty much any bug fix could be considered a breaking change - but could be persuaded that it's a break and should go into 8.x. Either way, this has to be fixed.

I have this on my of things to do/fix, but you - or anyone else - are welcome to do it. I also have noted that elementAt, find and takeWhile have - or might have? - a similar issue. If those other ops do have the bug, they should be fixed in separate PRs - for a neater CHANGELOG.

@benlesh
Copy link
Member

benlesh commented May 10, 2021

Hmm... I just closed that issue as "not a bug". It seems more like a misunderstanding in the order of execution. I'll reopen because I'm interested in other opinions.

@backbone87
Copy link
Contributor Author

while checking out take, i noticed that it also doesn't handle non-ints very well either.

imho, it should either check for Number.MAX_SAFE_INTEGER and floor the count or try to deal with all numbers (the latter can be problematic because of incrementing doesn't work past Number.MAX_SAFE_INTEGER

@benlesh
Copy link
Member

benlesh commented May 10, 2021

@backbone87 ... probably a separate issue to address.

I do have a fix for take, though. Let's add a skip to this test and get it merged, and I'll have a look.

@backbone87
Copy link
Contributor Author

backbone87 commented May 10, 2021

ah we pushed at the same time

fwiw here is the fixed I prepared locally:

    const connection = new OperatorSubscriber<T>(subscriber, (value) => {
      if (++seen === count) {
        // unsubscribe from the source if we have taken enough after the current
        // value. needs to be done before notifying downstream, so we dont get
        // any more notifications from upstream through sync recursion
        connection.unsubscribe();
        subscriber.next(value);
        subscriber.complete();
      } else if (seen < count) {
        subscriber.next(value);
      }
    });

    source.subscribe(connection);

though this causes a whitebox test for delayWhen to fail

@cartant
Copy link
Collaborator

cartant commented May 10, 2021

Probably want to remove the breaking change label from the description if this is gonna be merged as just a test.

Also, the reason I deem this a bug is because the operator is knowingly letting stuff - side effects - happen when it could immediately unsubscribe.

And, FWIW, the fix I was gonna make was basically what's

@backbone87
Copy link
Contributor Author

feel free to edit around the PR & branch, I wont push anymore now to avoid any more conflicts since @benlesh is working on it

@benlesh
Copy link
Member

benlesh commented May 10, 2021

@cartant yeah, we're already handling reentrancy in the next case, just not in the error and complete cases. This fix is simple enough.

@benlesh benlesh merged commit 9531c08 into ReactiveX:master May 10, 2021
@benlesh
Copy link
Member

benlesh commented May 10, 2021

Thanks for this, @backbone87, very helpful!

@backbone87 backbone87 deleted the fix/take-sync-error branch May 10, 2021 23:27
@cartant
Copy link
Collaborator

cartant commented May 10, 2021

Now that you're a contributor, @backbone87, I don't have to approve CI runs on your PRs. 🎉

@backbone87 backbone87 changed the title fix(take): notifies errors after limit is reached chore(take): test case for error notification after limit is reached May 10, 2021
@benlesh
Copy link
Member

benlesh commented May 10, 2021

Follow up PR is here: #6396

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.

first/tap operators should unsubscribe before emit next value
3 participants