From 555abc193e849ac160ce16c208f5c494975a0e97 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Thu, 25 Apr 2019 13:40:25 +0100 Subject: [PATCH] CORDA-2886 - Better handling of authentication error when re-connecting to RPC in RpcReconnectTest (#5052) --- .../corda/client/rpc/internal/ReconnectingCordaRPCOps.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/ReconnectingCordaRPCOps.kt b/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/ReconnectingCordaRPCOps.kt index 4df7c02f8c..dd603fd116 100644 --- a/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/ReconnectingCordaRPCOps.kt +++ b/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/ReconnectingCordaRPCOps.kt @@ -179,7 +179,8 @@ class ReconnectingCordaRPCOps private constructor( return currentRPCConnection!! } - private tailrec fun establishConnectionWithRetry(retryInterval: Duration = 1.seconds, nrRetries: Int = 0): CordaRPCConnection { + private tailrec fun establishConnectionWithRetry(retryInterval: Duration = 1.seconds, currentAuthenticationRetries: Int = 0): CordaRPCConnection { + var _currentAuthenticationRetries = currentAuthenticationRetries log.info("Connecting to: $nodeHostAndPorts") try { return CordaRPCClient( @@ -196,7 +197,7 @@ class ReconnectingCordaRPCOps private constructor( is ActiveMQSecurityException -> { // Happens when incorrect credentials provided. // It can happen at startup as well when the credentials are correct. - if (nrRetries > 1) { + if (_currentAuthenticationRetries++ > 1) { log.error("Failed to login to node.", ex) throw ex } @@ -222,7 +223,7 @@ class ReconnectingCordaRPCOps private constructor( // Could not connect this time round - pause before giving another try. Thread.sleep(retryInterval.toMillis()) // TODO - make the exponential retry factor configurable. - return establishConnectionWithRetry((retryInterval * 10) / 9, nrRetries + 1) + return establishConnectionWithRetry((retryInterval * 10) / 9, _currentAuthenticationRetries) } override val proxy: CordaRPCOps