Skip to content

IllegalReferenceCountException: refCnt: 0 when doing RSocketConnector.reconnect() #842

Closed

Description

@mostroverkhov

With simple server

public static void main(String[] args) {
        CloseableChannel server = RSocketServer.create().acceptor((setup, sendingSocket) -> Mono.just(new AbstractRSocket() {
            @Override
            public Mono<Payload> requestResponse(Payload payload) {
                payload.release();
                return Mono.just(ByteBufPayload.create("response"));
            }
        })).bind(TcpServerTransport.create(7078))
                .block();

        server.onClose().block();
    }

and client

@Test
    void retry() {

        Mono<RSocket> rSocketMono =
                RSocketConnector.create()
                        .setupPayload(ByteBufPayload.create("data", "metadata"))
                        .reconnect(
                                Retry.backoff(Integer.MAX_VALUE, Duration.ofMillis(100))
                                        .maxBackoff(Duration.ofMillis(500))
                                        .doBeforeRetry(s -> System.out.println("Before retry: " + s)))
                        .connect(() -> TcpClientTransport.create(7078));

        Flux.interval(Duration.ofSeconds(1))
                .onBackpressureDrop()
                .flatMap(v -> rSocketMono.flatMap(rSocket ->
                        rSocket.requestResponse(ByteBufPayload.create("request"))
                                .onErrorResume(err -> {
                                    System.out.println("Error: " + err);
                                    return Mono.empty();
                                })))
                .doOnNext(payload -> {
                    String dataUtf8 = payload.getDataUtf8();
                    System.out.println("Response: " + dataUtf8);
                    payload.release();
                })
                .blockLast();
    }

After server is torn down/ started again, client does not reconnect and has refCnt: 0 in retry callbacks:

Response: response

Before retry: attempt #12 (12 in a row), last failure={io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: /0:0:0:0:0:0:0:1:7078}

Before retry: attempt #13 (13 in a row), last failure={io.netty.util.IllegalReferenceCountException: refCnt: 0}
Before retry: attempt #14 (14 in a row), last failure={io.netty.util.IllegalReferenceCountException: refCnt: 0}
Before retry: attempt #15 (15 in a row), last failure={io.netty.util.IllegalReferenceCountException: refCnt: 0}



Activity

  1. added this to the 1.0.1 milestone on May 18, 2020
  2. OlegDokuka commented on May 18, 2020

    @OlegDokuka
    Member

    Indeed. That is a bug. Thanks for reporting that finding @mostroverkhov.

    I believe that the proper solution for that would be providing .setupPayload(Supplier<SetupPayload> payloadSupplier) and documenting behavior with reconnect. What do you think @rstoyanchev

  3. rstoyanchev commented on May 19, 2020

    @rstoyanchev
    Contributor

    Perhaps we could make it more transparent, e.g. when reconnect is on, make a copy of the setup/data payloads or use an extra retain for each use.

  4. removed this from the 1.0.1 milestone on May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsupersededIssue is superseded by another

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions