Skip to content

WebFlux: Mono does not invoke onComplete(), but instead cancel() #22952

@RobWin

Description

@RobWin

Affects: 5.1.6.RELEASE

Hello,

How to reproduce:
When I have a simple @RestController:

@GetMapping("monoSuccess")
public Mono<String> monoSuccess(){
    return Mono.just("test").log();
}

I can see in the Reactor logs the following:

[ctor-http-nio-3] reactor.Mono.Just.1 : | onSubscribe([Synchronous Fuseable] Operators.ScalarSubscription)
[ctor-http-nio-3] reactor.Mono.Just.1 : | request(unbounded)
[ctor-http-nio-3] reactor.Mono.Just.1 : | onNext(test)
[ctor-http-nio-3] reactor.Mono.Just.1 : | cancel()

This behavior does not match the bahavior of Flux.

@GetMapping("fluxSuccess")
public Flux<String> fluxSuccess(){
        return Flux.just("test") .log();
}
reactor.Flux.Just.1 : | onSubscribe([Fuseable] FluxJust.WeakScalarSubscription)
reactor.Flux.Just.1 : | request(1)
reactor.Flux.Just.1 : | onNext(test)
reactor.Flux.Just.1 : | request(32)
reactor.Flux.Just.1 : | onComplete()

My expectation:

  • I would expect that Mono and Flux behavior similar.
  • I would expect that onComplete() is invoked instead of ScalarSubscription.cancel() after onNext.

My problem :
When I do a simple test with my Resilience4j CircuitBreaker operator I can see the expected behavior of Reactor.

 StepVerifier.create(
    Mono.just("Event")
      .log()
      .transform(CircuitBreakerOperator.of(circuitBreaker))
      .log())
    .expectNext("Event")
    .verifyComplete();
reactor.Mono.Just.1 - | onSubscribe([Synchronous Fuseable] Operators.ScalarSubscription)
reactor.Mono.CircuitBreaker.2 - onSubscribe(CircuitBreakerSubscriber)
reactor.Mono.CircuitBreaker.2 - request(unbounded)
reactor.Mono.Just.1 - | request(unbounded)
reactor.Mono.Just.1 - | onNext(Event)
reactor.Mono.CircuitBreaker.2 - onNext(Event)
reactor.Mono.Just.1 - | onComplete()
reactor.Mono.CircuitBreaker.2 - onComplete()

My custom CircuitBreaker operator handles onComplete as a successful call and onError as a failed call. But onEvent is just forwarded to the downstream subscriber.
With the current unexpected behavior I have to handle onEvent specially when a Mono is decorated.

Kind regards,

Robert

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions