Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Work around cancel() after complete() wrong behavior in reactive-grpc #143

Closed

Conversation

ericbottard
Copy link
Contributor

@ericbottard ericbottard commented Oct 1, 2019

@ericbottard
Copy link
Contributor Author

Thanks to @bsideup and @simonbasle for the investigation work and fix!

// Used to transform the publisher chain into one that doesn't forward cancel() calls once it has complete()d.
private Function<? super Publisher<Tuple2<Integer, Message<byte[]>>>, ? extends Publisher<Tuple2<Integer, Message<byte[]>>>> ignoreCancelsAfterComplete() {
return Operators.lift((f, actual) ->
new CoreSubscriber<>() {
Copy link

Choose a reason for hiding this comment

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

FTR this can be optimized by implementing both CoreSubscriber and Subscription, something like:

class NoCancelAfterCompleteSubscriber<T> implements CoreSubscriber<T>, Subscription {

    @Override
    public void onSubscribe(s) { actual.onSubscribe(this); }
}

return new NoCancelAfterCompleteSubscriber<>();

although this is a very specific optimization can may be ignored if the performance of this part is not critical

private Function<? super Publisher<Tuple2<Integer, Message<byte[]>>>, ? extends Publisher<Tuple2<Integer, Message<byte[]>>>> ignoreCancelsAfterComplete() {
return Operators.lift((f, actual) ->
new CoreSubscriber<>() {
AtomicBoolean completed = new AtomicBoolean();
Copy link

Choose a reason for hiding this comment

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

since we don't need atomic CAS operation in onComplete, you could also use volatile boolean completed = false instead of +1 allocating AtomicBoolean

@ericbottard ericbottard force-pushed the workaround-cancel-on-input branch from dc9bde9 to 2ccbbba Compare October 1, 2019 17:30
@ericbottard ericbottard force-pushed the workaround-cancel-on-input branch from 2ccbbba to 8cab801 Compare October 2, 2019 13:19
@ericbottard
Copy link
Contributor Author

This has been merged already

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants