From 06e91a2e93280dfdd2d6dfe3782c81ab618cbaa4 Mon Sep 17 00:00:00 2001 From: Sheikah45 Date: Fri, 13 Oct 2023 12:24:59 -0400 Subject: [PATCH] Clean up retry logic --- .../faforever/commons/lobby/FafLobbyClient.kt | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/faf-commons-lobby/src/main/kotlin/com/faforever/commons/lobby/FafLobbyClient.kt b/faf-commons-lobby/src/main/kotlin/com/faforever/commons/lobby/FafLobbyClient.kt index ecc849f7..5947e047 100644 --- a/faf-commons-lobby/src/main/kotlin/com/faforever/commons/lobby/FafLobbyClient.kt +++ b/faf-commons-lobby/src/main/kotlin/com/faforever/commons/lobby/FafLobbyClient.kt @@ -81,10 +81,7 @@ class FafLobbyClient( is LoginSuccessResponse -> Mono.just(it.me) is LoginFailedResponse -> Mono.error(LoginException(it.text)) } - }.timeout(outboundMessages.ofType(SessionRequest::class.java) - .next() - .then(Mono.delay(Duration.ofSeconds(10))) - .timeout(Duration.ofMinutes(1), Mono.empty())) + }.timeout(Duration.ofSeconds(10)) .doOnError(LoginException::class.java) { kicked = true } .doFirst { prepareAuthenticateOnNextSession() @@ -92,10 +89,9 @@ class FafLobbyClient( } private val loginMono = Mono.defer { - connectionAcquired.next().then(loginResponseMono.retryWhen(createRetrySpec(config))).doFirst { - connectionDisposable?.dispose() - connectionDisposable = openConnection() - } + connectionAcquired.next().then(loginResponseMono).doFirst { + openConnection() + }.retryWhen(createRetrySpec(config)) } .doOnError { LOG.error("Error during connection", it); connection?.dispose() } .doOnCancel { LOG.debug("Login cancelled"); disconnect() } @@ -154,9 +150,10 @@ class FafLobbyClient( }.subscribe() } - private fun openConnection(): Disposable { + private fun openConnection() { LOG.debug("Opening connection") - return webSocketClient + connectionDisposable?.dispose() + connectionDisposable = webSocketClient .uri(config.url) .handle { inbound, outbound -> val inboundMono = inbound.receive()