0

I init my rsocket client with retry as follow:


        Mono<RSocketRequester> requesterMono = rsocketRequesterBuilder.setupRoute(SETUP_ROUTE)
            .setupData(new ObjectMapper().writeValueAsString(getAuthInfo()))
            .dataMimeType(MimeTypeUtils.parseMimeType(WellKnownMimeType.APPLICATION_JSON.getString()))
            .rsocketConnector(connector -> connector.acceptor(responder)
                .fragment(MTU_BYTE_SIZE)
                .keepAlive(Duration.ofSeconds(KEEP_ALIVE_INTERVAL_SEC), Duration.ofSeconds(KEEP_ALIVE_MAX_TIME_SEC))
                .reconnect(Retry.fixedDelay(Integer.MAX_VALUE, Duration.ofSeconds(RSOCKET_RETRY_INTERVAL_SECONDS))
                    .doAfterRetry(retrySignal -> log.warn("RSocket client is reconnecting to get the newest connection...."))))
            .connect(TcpClientTransport.create(TcpClient.create()
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, sidecarConfig.getRConnectTimeOutMs())
                .option(ChannelOption.SO_KEEPALIVE, true)
                .option(ChannelOption.TCP_NODELAY, true)
                .host(consoleDomain)
                .port(sidecarConfig.getConsoleRSocketPort())
                .secure(ssl -> ssl.sslContext(sslContext))));

 requesterMono.block(Duration.ofSeconds(FIRST_WAIT_TIMEOUT_SEC)).rsocket().onClose().doOnError(error -> {
            String errMsg = "[RSOCKET] connection close by fatal error, and client will exit.msg: " + ExceptionUtils.getRootCauseMessage(error);
            log.error(errMsg, error);
            doExit();
        }).doFinally(consumer -> log.info("[RSOCKET] sidecar client DISCONNECTED to console")).subscribe();

What I expected: Only fatal error will cause client to exit and when client meet other common exception like connection exception and error, it can retry automatically.

What actually occur: I found the connection error exception caused by keep alive will also get into the onError logic, and the client will exit.

My question is, whether the expectation I proposed is resonable and why? If it is resonable, how can I enable retry when code get into onError logic? If it is not resonable, how I understand the relationship between onError and retry? Why I should not retry when occur onError?

Kami Wan
  • 724
  • 2
  • 9
  • 23
  • please see this issue for a reference https://github.com/rsocket/rsocket-java/issues/987 – Oleh Dokuka Jun 27 '22 at 10:41
  • @OlehDokuka Retry works in my case in most time except the case when I meet exception like io.rsocket.exceptions.ConnectionErrorException: No keep-alive acks for 30000 ms. My question is how make rsocket retry even I meet such error and get into the onError logic. BTW, happy to see you again, my old friend~ – Kami Wan Jun 27 '22 at 11:59
  • You can do it with `RSocketRequester` but it requires some minor hacks as of now. In the future we will add that possibility as a setup option as well. Please refer to the GitHub discussion for more info – Oleh Dokuka Jun 27 '22 at 19:56
  • https://github.com/rsocket/rsocket-java/issues/987#issuecomment-795092496 – Oleh Dokuka Jun 28 '22 at 09:28
  • @KamiWan did you manage to make this work? – Robert Engel Dec 29 '22 at 11:42
  • @RobertEngel Not yet, maybe we should wait the new feature of rsocket – Kami Wan Dec 31 '22 at 10:44

0 Answers0