Skip to content

WebsocketOutbound sendClose never returns when nested #444

@rstoyanchev

Description

@rstoyanchev

Originally reported for WebFlux in SPR-17306 but I was able to confirm with just Reactor Netty that when a call to out.sendClose is nested within the pipeline for the write publisher, then the close does not complete. The following times out:

DisposableServer server = HttpServer.create()
    .tcpConfiguration(s -> s.host("0.0.0.0"))
    .port(0)
    .handle((req, resp) ->
        resp.sendWebsocket(null, (in, out) -> {
          return out.sendObject(Flux.error(new Throwable())
              .onErrorResume(ex -> out.sendClose(1001, "Going Away"))
              .cast(WebSocketFrame.class));

        }))
    .bind()
    .block();


HttpClient.create().websocket()
    .uri("http://0.0.0.0:" + server.address().getPort())
    .handle((in, out) -> in.receiveFrames().then()).next().block(Duration.ofSeconds(5));

However if the write and close are in a sequence, then it works:

DisposableServer server = HttpServer.create()
    .tcpConfiguration(s -> s.host("0.0.0.0"))
    .port(0)
    .handle((req, resp) ->
        resp.sendWebsocket(null, (in, out) -> {

          Flux<WebSocketFrame> writeFlux = Flux.error(new Throwable())
              .onErrorResume(ex -> Flux.empty())
              .cast(WebSocketFrame.class);

          return out.sendObject(writeFlux)
              .then(Mono.defer(() -> out.sendClose(1001, "Going Away")));

        }))
    .bind()
    .block();

I've confirmed the above with Californium only but the issue was reported against Spring Framework 5.0.9 which is based on Bismuth-SR11.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions