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
This commit is contained in:
Adel El-Beik 2020-03-03 12:10:04 +00:00 committed by GitHub
parent bd197b5229
commit b86ae0d6a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ import net.corda.client.jackson.JacksonSupport
import net.corda.client.rpc.CordaRPCClient import net.corda.client.rpc.CordaRPCClient
import net.corda.client.rpc.CordaRPCConnection import net.corda.client.rpc.CordaRPCConnection
import net.corda.client.rpc.GracefulReconnect import net.corda.client.rpc.GracefulReconnect
import net.corda.client.rpc.RPCException
import net.corda.core.internal.errors.AddressBindingException import net.corda.core.internal.errors.AddressBindingException
import net.corda.core.messaging.CordaRPCOps import net.corda.core.messaging.CordaRPCOps
import net.corda.core.utilities.contextLogger import net.corda.core.utilities.contextLogger
@ -34,7 +35,8 @@ import javax.servlet.http.HttpServletRequest
class NodeWebServer(val config: WebServerConfig) { class NodeWebServer(val config: WebServerConfig) {
private companion object { private companion object {
private val log = contextLogger() 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 val address = config.webAddress
@ -186,13 +188,26 @@ class NodeWebServer(val config: WebServerConfig) {
private lateinit var rpc: CordaRPCConnection private lateinit var rpc: CordaRPCConnection
private fun reconnectingCordaRPCOps(): CordaRPCOps { private fun reconnectingCordaRPCOps(): CordaRPCOps {
rpc = CordaRPCClient(config.rpcAddress, null, javaClass.classLoader) var retryCount = NODE_CONNECT_RETRY_COUNT
.start( while (true) {
config.runAs.username, try {
config.runAs.password, rpc = CordaRPCClient(config.rpcAddress, null, javaClass.classLoader)
GracefulReconnect() .start(
) config.runAs.username,
return rpc.proxy config.runAs.password,
GracefulReconnect()
)
return rpc.proxy
}
catch (ex: RPCException) {
if (retryCount-- == 0) {
throw ex
}
else {
Thread.sleep(NODE_CONNECT_WAIT_BETWEEN_RETRYS)
}
}
}
} }
/** /**