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

Bug in buffer or bufferCount operation when used with subject #1754

Closed
iFadey opened this issue Jun 8, 2016 · 2 comments · Fixed by #5654
Closed

Bug in buffer or bufferCount operation when used with subject #1754

iFadey opened this issue Jun 8, 2016 · 2 comments · Fixed by #5654
Assignees
Labels
bug Confirmed bug

Comments

@iFadey
Copy link

iFadey commented Jun 8, 2016

RxJS version: 5.0.0-beta.8

Code to reproduce:
https://jsfiddle.net/iFadey/qahvL1dm/

let section = document.querySelector('section');
let subject = new Rx.Subject();

Rx.Observable.fromEvent(section, 'click')
.subscribe(e => subject.next(e))
;

subject.buffer(subject.bufferCount(2))
.subscribe(x => console.log(x))
;

Expected behavior:
On first two clicks on section element must print pair of two event objects.

Actual behavior:
It prints single event object on first two clicks. Afterwards it starts printing correct pair.

Additional information:
I verified it in RxJS 4 and it works correctly with that version.

@benlesh
Copy link
Member

benlesh commented Jun 8, 2016

To narrow this down, what you're seeing is happening in buffer. The same behavior occurs with subject.buffer(subject.take(2)). This seems a little edge-casey, and might be a quirk with changes to default scheduling, but, for now I'll label it as a bug until we can confirm otherwise, since it is odd.

@benlesh benlesh added bug Confirmed bug help wanted Issues we wouldn't mind assistance with. labels Jun 8, 2016
@kwonoj kwonoj removed the help wanted Issues we wouldn't mind assistance with. label Dec 13, 2016
@mpodlasin
Copy link
Contributor

mpodlasin commented Dec 16, 2016

Currently on

const source = Observable.from([1,2,3,4,5,6]);
source.buffer(source.take(2));

RxJS 4 returns:

[1]
[2]
[]
// complete

This last array is last opened buffer, which did not have time to be populated with values, since right after it's opening take(2) completes stream.

The same code in RxJS 5 results in:

[]
[]
// complete

There are actually two differences here: first is obvious subscription order bug, that was fixed here: #2195

On that branch results are:

[1]
[2]
// complete

So second problem is that last one array. Currently code

Observable.never().buffer(Observable.empty());

in RxJS 4 results in

[]
// complete

and in RxJS 5

// complete

So real question here is: when selector stream completes do we want to return last initiated buffer?

There is also similar bug fix #2174, but in other direction - it emits last buffer once source observable completes

benlesh added a commit to benlesh/rxjs that referenced this issue Aug 18, 2020
- Resolves an issue where a multicast observable could not adequately be used to notify a buffer on itself
- Corrects a regression that was introduced by a bad merge back in 6.0. This was originally corrected in PR ReactiveX#2195.

fixes ReactiveX#1754
@benlesh benlesh self-assigned this Aug 18, 2020
benlesh added a commit that referenced this issue Sep 1, 2020
- Resolves an issue where a multicast observable could not adequately be used to notify a buffer on itself
- Corrects a regression that was introduced by a bad merge back in 6.0. This was originally corrected in PR #2195.

fixes #1754
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants