From b4a5a03992052b8380382ab82f327bc317ce68ca Mon Sep 17 00:00:00 2001 From: josecoll Date: Fri, 23 Dec 2016 15:09:13 +0000 Subject: [PATCH] Fixed issue caused by race condition in process registration v node exit. See https://github.com/corda/corda/issues/88 --- .../kotlin/net/corda/node/driver/Driver.kt | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/driver/Driver.kt b/node/src/main/kotlin/net/corda/node/driver/Driver.kt index d17c4d8d18..03617274f6 100644 --- a/node/src/main/kotlin/net/corda/node/driver/Driver.kt +++ b/node/src/main/kotlin/net/corda/node/driver/Driver.kt @@ -264,7 +264,7 @@ open class DriverDSL( private val networkMapAddress = portAllocation.nextHostAndPort() class State { - val registeredProcesses = LinkedList() + val registeredProcesses = LinkedList>() val clients = LinkedList() } @@ -279,12 +279,12 @@ open class DriverDSL( Paths.get(quasarFileUrl.toURI()).toString() } - fun registerProcess(process: Process) = state.locked { registeredProcesses.push(process) } + fun registerProcess(process: ListenableFuture) = state.locked { registeredProcesses.push(process) } override fun waitForAllNodesToFinish() { state.locked { registeredProcesses.forEach { - it.waitFor() + it.getOrThrow().waitFor() } } } @@ -294,7 +294,9 @@ open class DriverDSL( clients.forEach { it.stop() } - registeredProcesses.forEach(Process::destroy) + registeredProcesses.forEach { + it.get().destroy() + } } /** Wait 5 seconds, then [Process.destroyForcibly] */ val finishedFuture = executorService.submit { @@ -306,7 +308,7 @@ open class DriverDSL( finishedFuture.cancel(true) state.locked { registeredProcesses.forEach { - it.destroyForcibly() + it.get().destroyForcibly() } } } @@ -368,8 +370,9 @@ open class DriverDSL( configOverrides = configOverrides ) - return startNode(executorService, FullNodeConfiguration(config), quasarJarPath, debugPort).map { - registerProcess(it) + val startNode = startNode(executorService, FullNodeConfiguration(config), quasarJarPath, debugPort) + registerProcess(startNode) + return startNode.map { NodeHandle(queryNodeInfo(apiAddress)!!, config, it) } } @@ -409,7 +412,7 @@ open class DriverDSL( startNetworkMapService() } - private fun startNetworkMapService(): ListenableFuture { + private fun startNetworkMapService(): ListenableFuture { val apiAddress = portAllocation.nextHostAndPort() val debugPort = if (isDebug) debugPortAllocation.nextPort() else null @@ -428,9 +431,9 @@ open class DriverDSL( ) log.info("Starting network-map-service") - return startNode(executorService, FullNodeConfiguration(config), quasarJarPath, debugPort).map { - registerProcess(it) - } + val startNode = startNode(executorService, FullNodeConfiguration(config), quasarJarPath, debugPort) + registerProcess(startNode) + return startNode } companion object {