Skip to content

Conversation

davidmoten
Copy link
Collaborator

The request method used logic that could overrequest upstream if multiple small requests were made before the next item arrived.

Added a unit test that failed on previous code.

// ensure we only request as much as needed, no more no less
while (true) {
long r = requested.get();
long c = Math.min(n, limit - requested.get());
Copy link
Member

Choose a reason for hiding this comment

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

Re-read of a volatile value, you need limit - r.

@davidmoten
Copy link
Collaborator Author

Thanks @akarnokd. Changes made.

@akarnokd
Copy link
Member

Great job!

akarnokd added a commit that referenced this pull request May 29, 2015
prevent take() from requesting more than needed
@akarnokd akarnokd merged commit da588a2 into ReactiveX:1.x May 29, 2015
@akarnokd akarnokd added the Bug label May 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants