[CORDA-2923] Prevent connection threads leaking on reconnect (#5313)

This commit is contained in:
James Higgs 2019-07-19 15:28:44 +01:00 committed by Rick Parker
parent 06e709f86b
commit a204b50f5b
2 changed files with 6 additions and 4 deletions

View File

@ -91,10 +91,10 @@ class RPCStabilityTests {
block()
}
val threadsAfter = waitUntilNumberOfThreadsStable(executor)
// This is a less than check because threads from other tests may be shutting down while this test is running.
// This is therefore a "best effort" check. When this test is run on its own this should be a strict equality.
// In case of failure we output the threads along with their stacktraces to get an idea what was running at a time.
require(threadsBefore.keys.size >= threadsAfter.keys.size) { "threadsBefore: $threadsBefore\nthreadsAfter: $threadsAfter" }
val newThreads = threadsAfter.keys.minus(threadsBefore.keys)
require(newThreads.isEmpty()) {
"Threads have leaked. New threads created: $newThreads (total before: ${threadsBefore.size}, total after: ${threadsAfter.size})"
}
} finally {
executor.shutdownNow()
}

View File

@ -157,6 +157,8 @@ class ReconnectingCordaRPCOps private constructor(
*/
@Synchronized
fun reconnectOnError(e: Throwable) {
// Ensure any resources on this side are cleaned up before building a new connection
currentRPCConnection?.close()
currentState = CurrentState.DIED
//TODO - handle error cases
log.error("Reconnecting to ${this.nodeHostAndPorts} due to error: ${e.message}")