From b86ae0d6a64c909cfc19239dc1b9fb5eb9185d83 Mon Sep 17 00:00:00 2001 From: Adel El-Beik <48713346+adelel1@users.noreply.github.com> Date: Tue, 3 Mar 2020 12:10:04 +0000 Subject: [PATCH] Web server fails to connect to node if node takes too long to startup (#6012) * CORDA-3557: The web server attempts to reconnect to the client for a minute if initial attempt fails. * CORDA-3557: Fixing detekt issues --- .../corda/webserver/internal/NodeWebServer.kt | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/testing/testserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt b/testing/testserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt index 477c03e4b2..52dce3a5b7 100644 --- a/testing/testserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt +++ b/testing/testserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt @@ -6,6 +6,7 @@ import net.corda.client.jackson.JacksonSupport import net.corda.client.rpc.CordaRPCClient import net.corda.client.rpc.CordaRPCConnection import net.corda.client.rpc.GracefulReconnect +import net.corda.client.rpc.RPCException import net.corda.core.internal.errors.AddressBindingException import net.corda.core.messaging.CordaRPCOps import net.corda.core.utilities.contextLogger @@ -34,7 +35,8 @@ import javax.servlet.http.HttpServletRequest class NodeWebServer(val config: WebServerConfig) { private companion object { private val log = contextLogger() - const val retryDelay = 1000L // Milliseconds + private const val NODE_CONNECT_RETRY_COUNT = 30 + private const val NODE_CONNECT_WAIT_BETWEEN_RETRYS = 2000L } val address = config.webAddress @@ -186,13 +188,26 @@ class NodeWebServer(val config: WebServerConfig) { private lateinit var rpc: CordaRPCConnection private fun reconnectingCordaRPCOps(): CordaRPCOps { - rpc = CordaRPCClient(config.rpcAddress, null, javaClass.classLoader) - .start( - config.runAs.username, - config.runAs.password, - GracefulReconnect() - ) - return rpc.proxy + var retryCount = NODE_CONNECT_RETRY_COUNT + while (true) { + try { + rpc = CordaRPCClient(config.rpcAddress, null, javaClass.classLoader) + .start( + config.runAs.username, + config.runAs.password, + GracefulReconnect() + ) + return rpc.proxy + } + catch (ex: RPCException) { + if (retryCount-- == 0) { + throw ex + } + else { + Thread.sleep(NODE_CONNECT_WAIT_BETWEEN_RETRYS) + } + } + } } /**