CORDA-3281: Add a check for shutdown to avoid some of the errors (#5562)

from the reconnecting RPC when we know the server is going away
This commit is contained in:
Ryan Fowler 2019-10-09 13:43:22 +01:00 committed by Shams Asari
parent 712b8b7719
commit d983b7dd70

View File

@ -89,7 +89,12 @@ class ReconnectingCordaRPCOps private constructor(
*
* Note that this method does not guarantee 100% that the flow will not be started twice.
*/
fun runFlowWithLogicalRetry(runFlow: (CordaRPCOps) -> StateMachineRunId, hasFlowStarted: (CordaRPCOps) -> Boolean, onFlowConfirmed: () -> Unit = {}, timeout: Duration = 4.seconds) {
fun runFlowWithLogicalRetry(
runFlow: (CordaRPCOps) -> StateMachineRunId,
hasFlowStarted: (CordaRPCOps) -> Boolean,
onFlowConfirmed: () -> Unit = {},
timeout: Duration = 4.seconds
) {
try {
runFlow(this)
onFlowConfirmed()
@ -249,9 +254,8 @@ class ReconnectingCordaRPCOps private constructor(
}
}
private fun doInvoke(method: Method, args: Array<out Any>?): Any? {
// will stop looping when [method.invoke] succeeds
while (true) {
private tailrec fun doInvoke(method: Method, args: Array<out Any>?): Any? {
// will stop recursing when [method.invoke] succeeds
try {
log.debug { "Invoking RPC $method..." }
return method.invoke(reconnectingRPCConnection.proxy, *(args ?: emptyArray())).also {
@ -264,8 +268,10 @@ class ReconnectingCordaRPCOps private constructor(
reconnectingRPCConnection.reconnectOnError(e)
}
is ConnectionFailureException -> {
if (!reconnectingRPCConnection.proxy.isWaitingForShutdown()) {
log.error("Failed to perform operation ${method.name}. Connection dropped. Retrying....", e)
reconnectingRPCConnection.reconnectOnError(e)
}
checkIfIsStartFlow(method, e)
}
is RPCException -> {
@ -281,7 +287,7 @@ class ReconnectingCordaRPCOps private constructor(
}
}
}
}
return doInvoke(method, args)
}
override fun invoke(proxy: Any, method: Method, args: Array<out Any>?): Any? {