mirror of
https://github.com/corda/corda.git
synced 2025-01-30 16:14:39 +00:00
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:
parent
bd197b5229
commit
b86ae0d6a6
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user