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

OnSubscribeFromIterable - add request overflow check #2559

Merged
merged 1 commit into from
Jan 30, 2015

Conversation

davidmoten
Copy link
Collaborator

A subscriber like so provokes a hang from OnSubscribeFromIterable due to overflow to negative of requested field:

    @Override
    public void onStart() {
        request(2);
    }

    @Override
    public void onNext(Integer t) {
        request(Long.MAX_VALUE-1);
    }

I've moved the getAndAddRequest method that does the overflow check to a new rx.internal.operators.Util class that is also now used by the request overflow check in OperatorMerge.

Of course there are plenty more of these to be done. I propose to do them bit by bit.

@davidmoten
Copy link
Collaborator Author

REQUESTED get's reduced as well in this OnSubscribe. I'll ponder this and report what effects will be. Might make another change.

@akarnokd
Copy link
Member

I think BackpressureUtils would be a better name and an AtomicLong overload would be great.

@davidmoten
Copy link
Collaborator Author

Righto
On 29 Jan 2015 20:02, "David Karnok" [email protected] wrote:

I think BackpressureUtils would be a better name and an AtomicLong
overload would be great.


Reply to this email directly or view it on GitHub
#2559 (comment).

@davidmoten
Copy link
Collaborator Author

oops fixing the javadoc

@davidmoten
Copy link
Collaborator Author

Changes made as requested by @akarnokd. The bit I was pondering was what behaviour should be expected of an Observable when additive requests reach Long.MAX_VALUE. I came up with a policy that I added to the javadoc of Subscriber.request and Producer.request:

Requests are additive but if a sequence of requests totals more than Long.MAX_VALUE then Long.MAX_VALUE requests will be actioned and the extras may be ignored. Arriving at Long.MAX_VALUE by addition of requests cannot be assumed to disable backpressure. For example, the code below may result in Long.MAX_VALUE requests being actioned only.

request(100);
request(Long.MAX_VALUE-1);

@@ -23,6 +23,16 @@
/**
* Request a certain maximum number of items from this Producer. This is a way of requesting backpressure.
* To disable backpressure, pass {@code Long.MAX_VALUE} to this method.
* * <p>
Copy link
Member

Choose a reason for hiding this comment

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

Here is an extra * in the javadoc.

@davidmoten davidmoten force-pushed the from-iter-request-overflow branch from d7b63ad to 8496582 Compare January 30, 2015 11:09
@davidmoten
Copy link
Collaborator Author

fixed javadoc typo, squashed commits

@akarnokd
Copy link
Member

Good job! Merging.

akarnokd added a commit that referenced this pull request Jan 30, 2015
OnSubscribeFromIterable - add request overflow check
@akarnokd akarnokd merged commit cefc28d into ReactiveX:1.x Jan 30, 2015
@benjchristensen benjchristensen mentioned this pull request Feb 3, 2015
@davidmoten davidmoten deleted the from-iter-request-overflow branch April 10, 2015 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants