From 975866590b6ad0705501a27030791929f2559bbf Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 22 May 2017 12:18:53 +0100 Subject: [PATCH] Prevent DemoBench hanging on shutdown (#722) * We need to close the RPC client as otherwise the rpc-client-reaper-* thread is leaked, which also prevents shutdown. Sleep instead when the server exits, just long enough for the client to realise that the server is dead. * Fix warning about leaking private types. --- .../src/main/kotlin/net/corda/demobench/pty/R3Pty.kt | 7 +++++-- .../src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt | 3 +-- .../main/kotlin/net/corda/demobench/views/NodeTabView.kt | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/pty/R3Pty.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/pty/R3Pty.kt index feaa423299..68152fbfc1 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/pty/R3Pty.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/pty/R3Pty.kt @@ -11,7 +11,7 @@ import java.awt.Dimension import java.io.IOException import java.nio.charset.StandardCharsets.UTF_8 import java.util.concurrent.Executors -import java.util.concurrent.TimeUnit +import java.util.concurrent.TimeUnit.SECONDS class R3Pty(val name: X500Name, settings: SettingsProvider, dimension: Dimension, val onExit: (Int) -> Unit) : AutoCloseable { private companion object { @@ -37,7 +37,7 @@ class R3Pty(val name: X500Name, settings: SettingsProvider, dimension: Dimension return PtyProcessTtyConnector(name.commonName, process, UTF_8) } catch (e: Exception) { process.destroyForcibly() - process.waitFor(30, TimeUnit.SECONDS) + process.waitFor(30, SECONDS) throw e } } @@ -59,6 +59,8 @@ class R3Pty(val name: X500Name, settings: SettingsProvider, dimension: Dimension executor.submit { val exitValue = connector.waitFor() log.info("Terminal has exited (value={})", exitValue) + // TODO: Remove this arbitrary sleep when https://github.com/corda/corda/issues/689 is fixed. + try { Thread.sleep(SECONDS.toMillis(2)) } catch (e: InterruptedException) {} onExit(exitValue) } @@ -66,6 +68,7 @@ class R3Pty(val name: X500Name, settings: SettingsProvider, dimension: Dimension session.start() } + @Suppress("unused") @Throws(InterruptedException::class) fun waitFor(): Int? = terminal.ttyConnector?.waitFor() diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt index 70c124236f..e3d1f95c13 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt @@ -54,8 +54,7 @@ class NodeRPC(config: NodeConfig, start: (NodeConfig, CordaRPCOps) -> Unit, invo override fun close() { timer.cancel() try { - // TODO: Uncomment when https://github.com/corda/corda/issues/689 is fixed - // rpcConnection?.close() + rpcConnection?.close() } catch (e: Exception) { log.error("Failed to close RPC connection (Error: {})", e.message) } diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt index 6026e066a6..44a62537cb 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt @@ -41,7 +41,7 @@ class NodeTabView : Fragment() { const val textWidth = 465.0 val jvm by inject() - val cordappPathsFile = jvm.dataHome / "cordapp-paths.txt" + val cordappPathsFile: Path = jvm.dataHome / "cordapp-paths.txt" fun loadDefaultCordappPaths(): MutableList { if (cordappPathsFile.exists())