-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Mono.share() is canceled on subscription disposal #2680
Comments
we need to backtrack a bit, ensure which behavior is the "correct" one and better document the two operators behavior in face of cancellation, indeed. |
if we look at but actually, there is a special case in place for That means that calling Mono<Integer> mono = mono.just(1).share();
mono.subscribe().dispose();
mono.block(); The block() throws a We have to re-evaluate all of these internals :( |
I'm not sure what to do here in terms of timeline / milestone for changing this. Opened #2756 to explore a potential fix |
This commit makes changes to `NextProcessor`, splitting it into two classes: one deals with the (deprecated) pure processor aspect while the other implements the sink aspect. In order to align `Mono.share()` behavior with that of `Flux.share()`, several changes are introduced: - Each call to `mono.share().subscribe()` returns a dedicated `Disposable` - `mono.share()` behaves like a reference counted multicast, ie the same as `Flux#share`: individual subscribers can be cancelled and once all are gone, upstream is cancelled and next incoming subscriber will trigger an upstream re-subscription We avoid impacting `Sinks.one()` usages by introducing a dedicated `SinkOneMulticast` implementation. Accordingly, relevant tests in `NextProcessorTest` are copied and adapted in `SinkOneMulticastTest`. Fixes #2680.
Similarly to Flux#share, Mono#share also cancels the source when all Subscribers have cancelled. This change improves the documentation. Following #2680 and #2756 there exists a misalignment in the javadoc for Mono#share method. Since cancelling the source is a fact, the javadoc is now improved instead of changing the behaviour. Resolves #3740
Similarly to Flux#share, Mono#share also cancels the source when all Subscribers have cancelled. This change improves the documentation. Following #2680 and #2756 there exists a misalignment in the javadoc for Mono#share method. Since cancelling the source is a fact, the javadoc is now improved instead of changing the behaviour. Resolves #3740
Similarly to `Flux#share`, `Mono#share` also cancels the source when all `Subscriber`s have cancelled. This change improves the documentation. Following #2680 and #2756 there exists a misalignment in the javadoc for `Mono#share` method. Since cancelling the source is a fact, the javadoc is now improved instead of changing the behaviour. Resolves #3740
Expected Behavior
When doing
var sharedMono = innerMono.share()
, theinnerMono
should not be canceled if callingsharedMono.subscribe().dispose()
.At least, that's what the JavaDoc for
Mono.share()
suggests:It's worth noting this is an un-cancellable Subscription.
Actual Behavior
The
innerMono
is canceled.Steps to Reproduce
Prints
CANCELED
.By the way,
innerMono.cache().subscribe().dispose
does NOT cancelinnerMono
, although the JavaDoc makes no statement about cancellation behavior... (just replaceshare()
withcache()
in the example.Possible Solution
This might be a bug in the implementation or documentation, or simply me not understanding the documentation right.
Please also note that the marble diagram for
share()
needs a fix, too. (see itscancel()
arrow)Also, please consider documenting the cancellation behavior of
cache()
.Meanwhile, I will use
cache()
as a workaround. It might actually also make sense to document the difference between these two methods.Thanks a lot!
Your Environment
java -version
): 14.0.1uname -a
): MacOS 11.2.3The text was updated successfully, but these errors were encountered: