mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
ENT-5379 Reconnecting RPC fixed to recognize shutdown calls and break reconnect attempts (#6316)
This commit is contained in:
parent
ce672f50dd
commit
bfcd1d8791
@ -293,4 +293,27 @@ class CordaRPCClientReconnectionTest {
|
||||
.isInstanceOf(RPCException::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout=300_000)
|
||||
fun `rpc client does not attempt to reconnect after shutdown`() {
|
||||
driver(DriverParameters(cordappsForAllNodes = emptyList())) {
|
||||
val address = NetworkHostAndPort("localhost", portAllocator.nextPort())
|
||||
fun startNode(): NodeHandle {
|
||||
return startNode(
|
||||
providedName = CHARLIE_NAME,
|
||||
rpcUsers = listOf(CordaRPCClientTest.rpcUser),
|
||||
customOverrides = mapOf("rpcSettings.address" to address.toString())
|
||||
).getOrThrow()
|
||||
}
|
||||
|
||||
val node = startNode()
|
||||
val client = CordaRPCClient(node.rpcAddress, config)
|
||||
(client.start(rpcUser.username, rpcUser.password, gracefulReconnect = gracefulReconnect)).use {
|
||||
val rpcOps = it.proxy as ReconnectingCordaRPCOps
|
||||
rpcOps.shutdown()
|
||||
// If we get here we know we're not stuck in a reconnect cycle with a node that's been shut down
|
||||
assertThat(rpcOps.reconnectingRPCConnection.isClosed())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -311,13 +311,18 @@ class ReconnectingCordaRPCOps private constructor(
|
||||
checkIfClosed()
|
||||
var remainingAttempts = maxNumberOfAttempts
|
||||
var lastException: Throwable? = null
|
||||
while (remainingAttempts != 0) {
|
||||
while (remainingAttempts != 0 && !reconnectingRPCConnection.isClosed()) {
|
||||
try {
|
||||
log.debug { "Invoking RPC $method..." }
|
||||
return method.invoke(reconnectingRPCConnection.proxy, *(args ?: emptyArray())).also {
|
||||
log.debug { "RPC $method invoked successfully." }
|
||||
}
|
||||
} catch (e: InvocationTargetException) {
|
||||
if (method.name.equals("shutdown", true)) {
|
||||
log.debug("Shutdown invoked, stop reconnecting.", e)
|
||||
reconnectingRPCConnection.notifyServerAndClose()
|
||||
break
|
||||
}
|
||||
when (e.targetException) {
|
||||
is RejectedCommandException -> {
|
||||
log.warn("Node is being shutdown. Operation ${method.name} rejected. Retrying when node is up...", e)
|
||||
@ -349,6 +354,7 @@ class ReconnectingCordaRPCOps private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
if (reconnectingRPCConnection.isClosed()) return null
|
||||
throw MaxRpcRetryException(maxNumberOfAttempts, method, lastException)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user