Querying of node and webserver now uses infinite retries to avoid any race conditions.

This commit is contained in:
Clinton Alexander 2017-01-30 12:08:41 +00:00
parent d2ebcbfab0
commit a5f6fb9479

View File

@ -328,19 +328,14 @@ open class DriverDSL(
} }
private fun queryNodeInfo(nodeAddress: HostAndPort, sslConfig: SSLConfiguration): NodeInfo? { private fun queryNodeInfo(nodeAddress: HostAndPort, sslConfig: SSLConfiguration): NodeInfo? {
var retries = 0 while (true) try {
while (retries < 5) try {
val client = CordaRPCClient(nodeAddress, sslConfig) val client = CordaRPCClient(nodeAddress, sslConfig)
client.start(ArtemisMessagingComponent.NODE_USER, ArtemisMessagingComponent.NODE_USER) client.start(ArtemisMessagingComponent.NODE_USER, ArtemisMessagingComponent.NODE_USER)
val rpcOps = client.proxy(timeout = Duration.of(15, ChronoUnit.SECONDS)) val rpcOps = client.proxy(timeout = Duration.of(15, ChronoUnit.SECONDS))
return rpcOps.nodeIdentity() return rpcOps.nodeIdentity()
} catch(e: Exception) { } catch(e: Exception) {
log.error("Retrying query node info at $nodeAddress") log.error("Retrying query node info at $nodeAddress")
retries++
} }
log.error("Could not query node info after $retries retries")
return null
} }
override fun startNode(providedName: String?, advertisedServices: Set<ServiceInfo>, override fun startNode(providedName: String?, advertisedServices: Set<ServiceInfo>,
@ -425,10 +420,8 @@ open class DriverDSL(
} }
val url = URL(protocol + configuration.webAddress.toString() + "/api/status") val url = URL(protocol + configuration.webAddress.toString() + "/api/status")
val client = OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS).readTimeout(60, TimeUnit.SECONDS).build() val client = OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS).readTimeout(60, TimeUnit.SECONDS).build()
val retries = 50
for (i in 0..retries) { while (true) try {
try {
val response = client.newCall(Request.Builder().url(url).build()).execute() val response = client.newCall(Request.Builder().url(url).build()).execute()
if (response.isSuccessful && (response.body().string() == "started")) { if (response.isSuccessful && (response.body().string() == "started")) {
return configuration.webAddress return configuration.webAddress
@ -438,10 +431,6 @@ open class DriverDSL(
} }
} }
log.error("Could not query node info after $retries retries")
return null
}
override fun startWebserver(handle: NodeHandle): ListenableFuture<HostAndPort> { override fun startWebserver(handle: NodeHandle): ListenableFuture<HostAndPort> {
val debugPort = if (isDebug) debugPortAllocation.nextPort() else null val debugPort = if (isDebug) debugPortAllocation.nextPort() else null