mirror of
https://github.com/corda/corda.git
synced 2025-01-18 02:39:51 +00:00
[CORDA-2923] Prevent connection threads leaking on reconnect (#5313)
This commit is contained in:
parent
06e709f86b
commit
a204b50f5b
@ -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()
|
||||
}
|
||||
|
@ -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}")
|
||||
|
Loading…
Reference in New Issue
Block a user