fix for Could not reconnect to the RPC server“ error on shutdown via Shell-Cli (#6595)

an RPCUtils created to centralize method name related operations
This commit is contained in:
Tamas Veingartner 2020-08-10 09:51:24 +01:00 committed by GitHub
parent 922dbe8544
commit e234bd9c96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import net.corda.client.rpc.ConnectionFailureException
import net.corda.client.rpc.CordaRPCClientConfiguration
import net.corda.client.rpc.RPCException
import net.corda.client.rpc.RPCSinceVersion
import net.corda.client.rpc.internal.RPCUtils.isShutdownCmd
import net.corda.core.context.Actor
import net.corda.core.context.Trace
import net.corda.core.context.Trace.InvocationId
@ -342,7 +343,7 @@ internal class RPCClientProxyHandler(
"Generated several RPC requests with same ID $replyId"
}
if (request.methodName.equals("terminate", true)){
if (request.isShutdownCmd()){
terminating = true
}

View File

@ -0,0 +1,15 @@
package net.corda.client.rpc.internal
import net.corda.nodeapi.RPCApi
import java.lang.reflect.Method
object RPCUtils {
fun isShutdownMethodName(methodName: String) =
methodName.equals("shutdown", true) ||
methodName.equals("gracefulShutdown", true) ||
methodName.equals("terminate", true)
fun RPCApi.ClientToServer.RpcRequest.isShutdownCmd() = isShutdownMethodName(methodName)
fun Method.isShutdown() = isShutdownMethodName(name)
fun Method.isStartFlow() = name.startsWith("startFlow") || name.startsWith("startTrackedFlow")
}

View File

@ -10,6 +10,8 @@ import net.corda.client.rpc.PermissionException
import net.corda.client.rpc.RPCConnection
import net.corda.client.rpc.RPCException
import net.corda.client.rpc.UnrecoverableRPCException
import net.corda.client.rpc.internal.RPCUtils.isShutdown
import net.corda.client.rpc.internal.RPCUtils.isStartFlow
import net.corda.client.rpc.internal.ReconnectingCordaRPCOps.ReconnectingRPCConnection.CurrentState.CLOSED
import net.corda.client.rpc.internal.ReconnectingCordaRPCOps.ReconnectingRPCConnection.CurrentState.CONNECTED
import net.corda.client.rpc.internal.ReconnectingCordaRPCOps.ReconnectingRPCConnection.CurrentState.CONNECTING
@ -292,9 +294,6 @@ class ReconnectingCordaRPCOps private constructor(
fun isClosed(): Boolean = currentState == CLOSED
}
private class ErrorInterceptingHandler(val reconnectingRPCConnection: ReconnectingRPCConnection) : InvocationHandler {
private fun Method.isStartFlow() = name.startsWith("startFlow") || name.startsWith("startTrackedFlow")
private fun Method.isShutdown() = name == "shutdown" || name == "gracefulShutdown" || name == "terminate"
private fun checkIfIsStartFlow(method: Method, e: InvocationTargetException) {
if (method.isStartFlow()) {
// Don't retry flows

View File

@ -14,6 +14,7 @@ import net.corda.client.rpc.CordaRPCClientConfiguration
import net.corda.client.rpc.CordaRPCConnection
import net.corda.client.rpc.GracefulReconnect
import net.corda.client.rpc.PermissionException
import net.corda.client.rpc.internal.RPCUtils.isShutdownMethodName
import net.corda.client.rpc.notUsed
import net.corda.core.CordaException
import net.corda.core.concurrent.CordaFuture
@ -111,8 +112,6 @@ object InteractiveShell {
YAML
}
private fun isShutdownCmd(cmd: String) = cmd == "shutdown" || cmd == "gracefulShutdown" || cmd == "terminate"
fun startShell(configuration: ShellConfiguration, classLoader: ClassLoader? = null, standalone: Boolean = false) {
makeRPCConnection = { username: String, password: String ->
val connection = if (standalone) {
@ -625,7 +624,7 @@ object InteractiveShell {
throw e.rootCause
}
}
if (isShutdownCmd(cmd)) {
if (isShutdownMethodName(cmd)) {
out.println("Called 'shutdown' on the node.\nQuitting the shell now.").also { out.flush() }
onExit.invoke()
}