Skip to content

Mono.share() is canceled on subscription disposal #2680

@yamass

Description

@yamass

Expected Behavior

When doing var sharedMono = innerMono.share(), the innerMono should not be canceled if calling sharedMono.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

		Mono.create(monoSink -> {
			monoSink.onCancel(() -> {
				System.out.println("CANCELED");
			});
			monoSink.success("asdf");
		})
				.subscribeOn(Schedulers.boundedElastic())
				.share()
				.subscribe()
				.dispose();

		Thread.sleep(1000);

Prints CANCELED.

By the way, innerMono.cache().subscribe().dispose does NOT cancel innerMono, although the JavaDoc makes no statement about cancellation behavior... (just replace share() with cache() 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 its cancel() 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

  • Reactor version(s) used: 3.4.5
  • JVM version (java -version): 14.0.1
  • OS and version (eg uname -a): MacOS 11.2.3

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions