Skip to content

switchOnMap with single returned item cancels input #3936

@yawkat

Description

@yawkat

Expected Behavior

When a switchOnFirst function returns a single item that contains the input flux but is not derived through operators, the input flux should remain available without restriction.

Actual Behavior

The input flux is cancelled when the outer flux is cancelled (e.g. by Mono.from), making it unusable.

Steps to Reproduce

    public static void main(String[] args) {
        Flux<String> input = Flux.just("foo", "bar");
        Mono<Flux<String>> nested = Mono.from(input.switchOnFirst((first, all) -> Mono.just(all)));
        Flux<String> item = nested.block();
        System.out.println(item); // prints SwitchOnFirstMain as expected
        System.out.println(item.collectList().block()); // never terminates as the item has been cancelled
    }

Possible Solution

In the above example, Mono.from sees the onNext immediately, and cancels the FluxSwitchOnFirst. Cancelling FluxSwitchOnFirst however also cancels the SwitchOnFirstMain, which it should not. Cancellation should only be sent to the publisher returned by the switchOnFirst lambda (in this case the Mono.just)

Your Environment

  • Reactor version(s) used: 3.6.9
  • Other relevant libraries versions (eg. netty, ...): N/A

Metadata

Metadata

Assignees

Labels

status/invalidWe don't feel this issue is valid, or the root cause was found outside of Reactor

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions