CCF icon indicating copy to clipboard operation
CCF copied to clipboard

Rejoining after retire_node with same rpc-address is failing

Open iqsarv opened this issue 6 years ago • 9 comments

Describe the bug Node with same hostname:port as previous instance is unable to join the network even after retire

#375 mentions that when retired, it should be possible to rejoin with the same hostname:port

To Reproduce

  1. Node n0 is shutdown
  2. Node n0 is retired and global commit
  3. Join n0 to network with same hostname:port

Expected behavior Node n0 should join successfully

Error thrown

Node ccf-0 retires and rejoins


root@ccf-0:/opt/azure/ccf# ./memberclient --rpc-address ccf-1.ccf.default.svc.cluster.local.:3200 --cert certs/operator_cert.pem --privk certs/operator_privk.pem \
 --ca network_cert.pem retire_node --node-id 0
 {"commit":14,"global_commit":13,"id":0,"jsonrpc":"2.0","result":{"completed":true,"id":3},"term":4}
 
root@ccf-0:/opt/azure/ccf# ./cchost --enclave-file=libloggingenc.so.signed --consensus raft --enclave-type=debug --ledger-file=ccf4q.ledger --node-cert-file=node_cert.pem 
--quote-file=quote.bin --host-log-level=info --raft-election-timeout-ms=100000 --raft-timeout-ms=500
 --node-address=ccf-0.ccf.default.svc.cluster.local:3100 --rpc-address=ccf-0.ccf.default.svc.cluster.local:3200 
 --domain=ccf-0.ccf.default.svc.cluster.local join --network-cert-file=network_cert.pem --target-rpc-address ccf-1.ccf.default.svc.cluster.local.:3200

2020-02-03T11:29:41.263343Z        [info ] /tmp/CCF/src/host/main.cpp:376       | Creating new node - joining existing network at ccf-1.ccf.default.svc.cluster.local.:3200
2020-02-03T11:29:41.347594Z        [info ] /tmp/CCF/src/host/main.cpp:399       | Created new node
2020-02-03T11:29:41.349634Z -0.086 [info ] /tmp/CCF/src/node/nodestate.h:1089   | Node TLS connections now accepted
2020-02-03T11:29:41.674928Z -0.034 [fail ] /tmp/CCF/src/node/nodestate.h:444    | An error occurred while joining the network {"error":{"code":-32602,"message":"[INVALID_PARAMS]: A node with the same node host ccf-0.ccf.default.svc.cluster.local and port 3100 already exists (node id: 3)"},"id":1,"jsonrpc":"2.0"}
2020-02-03T11:29:42.536449Z -0.050 [fail ] /tmp/CCF/src/node/nodestate.h:444    | An error occurred while joining the network {"error":{"code":-32602,"message":"[INVALID_PARAMS]: A node with the same node host ccf-0.ccf.default.svc.cluster.local and port 3100 already exists (node id: 3)"},"id":2,"jsonrpc":"2.0"}
2020-02-03T11:29:43.543015Z -0.076 [fail ] /tmp/CCF/src/node/nodestate.h:444    | An error occurred while joining the network {"error":{"code":-32602,"message":"[INVALID_PARAMS]: A node with the same node host ccf-0.ccf.default.svc.cluster.local and port 3100 already exists (node id: 3)"},"id":3,"jsonrpc":"2.0"}
2020-02-03T11:29:44.588789Z -0.115 [fail ] /tmp/CCF/src/node/nodestate.h:444    | An error occurred while joining the network {"error":{"code":-32602,"message":"[INVALID_PARAMS]: A node with the same node host ccf-0.ccf.default.svc.cluster.local and port 3100 already exists (node id: 3)"},"id":4,"jsonrpc":"2.0"}

Node ccf-1 (stable and elected as leader again)

2020-02-03T11:13:27.270177Z        [fail ] /tmp/CCF/src/host/dns.h:68           | uv_getaddrinfo for host:service [ccf-0.ccf.default.svc.cluster.local:3100] failed with error unknown node or service
2020-02-03T11:16:08.746943Z -12.266 [info ] /tmp/CCF/src/node/channels.h:279     | node2node channel with 2 is now established
2020-02-03T11:16:47.922560Z -14.021 [info ] mp/CCF/src/consensus/raft/raft.h:985 | Becoming candidate 1: 3
2020-02-03T11:16:47.926930Z -14.025 [info ] mp/CCF/src/consensus/raft/raft.h:790 | Send request vote from 1 to 2
2020-02-03T11:16:47.927074Z -14.025 [info ] mp/CCF/src/consensus/raft/raft.h:790 | Send request vote from 1 to 0
2020-02-03T11:16:47.943252Z -14.029 [info ] mp/CCF/src/consensus/raft/raft.h:956 | Recv request vote response to 1 from 2: they voted no
2020-02-03T11:18:42.770928Z -19.022 [info ] mp/CCF/src/consensus/raft/raft.h:985 | Becoming candidate 1: 4
2020-02-03T11:18:42.771068Z -19.022 [info ] mp/CCF/src/consensus/raft/raft.h:790 | Send request vote from 1 to 2
2020-02-03T11:18:42.771200Z -19.022 [info ] mp/CCF/src/consensus/raft/raft.h:790 | Send request vote from 1 to 0
2020-02-03T11:18:42.790942Z -19.019 [info ] mp/CCF/src/consensus/raft/raft.h:963 | Recv request vote response to 1 from 2: they voted yes
2020-02-03T11:18:42.791048Z -19.019 [info ] p/CCF/src/consensus/raft/raft.h:1006 | Becoming leader 1: 4
2020-02-03T11:18:43.846928Z -19.075 [info ] /tmp/CCF/src/node/history.h:546      | Issuing signature at 7
2020-02-03T11:19:33.918950Z -21.351 [info ] CF/src/node/rpc/memberfrontend.h:147 | Node 0 is now TRUSTED
2020-02-03T11:19:33.923373Z        [fail ] p/CCF/src/host/nodeconnections.h:270 | Cannot add node 0: already in use
2020-02-03T11:19:34.337282Z -21.330 [info ] /tmp/CCF/src/node/history.h:546      | Issuing signature at 10
2020-02-03T11:19:35.135376Z        [fail ] p/CCF/src/host/nodeconnections.h:304 | Unknown node 0
2020-02-03T11:19:35.651117Z        [fail ] p/CCF/src/host/nodeconnections.h:304 | Unknown node 0
2020-02-03T11:19:36.183480Z        [fail ] p/CCF/src/host/nodeconnections.h:304 | Unknown node 0
2020-02-03T11:19:36.721187Z        [fail ] p/CCF/src/host/nodeconnections.h:304 | Unknown node 0
2020-02-03T11:19:37.247019Z        [fail ] p/CCF/src/host/nodeconnections.h:304 | Unknown node 0
2020-02-03T11:19:37.772624Z        [fail ] p/CCF/src/host/nodeconnections.h:304 | Unknown node 0
2020-02-03T11:19:38.302631Z        [fail ] p/CCF/src/host/nodeconnections.h:304 | Unknown node 0
2020-02-03T11:19:38.846987Z        [fail ] p/CCF/src/host/nodeconnections.h:304 | Unknown node 0

Node ccf-2 (stable and became follower)

2020-02-03T11:16:08.702925Z -11.732 [info ] mp/CCF/src/consensus/raft/raft.h:985 | Becoming candidate 2: 3
2020-02-03T11:16:08.702978Z -11.732 [info ] mp/CCF/src/consensus/raft/raft.h:790 | Send request vote from 2 to 1
2020-02-03T11:16:08.718982Z -11.748 [info ] mp/CCF/src/consensus/raft/raft.h:790 | Send request vote from 2 to 0
2020-02-03T11:16:08.782927Z -11.767 [info ] /tmp/CCF/src/node/channels.h:279     | node2node channel with 1 is now established
2020-02-03T11:16:47.931004Z -13.466 [info ] mp/CCF/src/consensus/raft/raft.h:884 | Send request vote response from 2 to 1: false
2020-02-03T11:18:42.778960Z -18.473 [info ] p/CCF/src/consensus/raft/raft.h:1042 | Becoming follower 2: 4
2020-02-03T11:18:42.778974Z -18.473 [info ] mp/CCF/src/consensus/raft/raft.h:884 | Send request vote response from 2 to 1: true
2020-02-03T11:18:43.870926Z -18.537 [info ] mp/CCF/src/consensus/raft/raft.h:664 | Deserialising signature at 7
2020-02-03T11:19:34.150995Z        [fail ] p/CCF/src/host/nodeconnections.h:270 | Cannot add node 0: already in use
2020-02-03T11:19:34.703502Z -20.820 [info ] mp/CCF/src/consensus/raft/raft.h:664 | Deserialising signature at 10
2020-02-03T11:26:30.636550Z -36.083 [info ] p/CCF/src/consensus/raft/raft.h:1228 | Added node 3
2020-02-03T11:26:30.638928Z -36.085 [info ] mp/CCF/src/consensus/raft/raft.h:664 | Deserialising signature at 13
2020-02-03T11:26:31.146975Z        [fail ] p/CCF/src/host/nodeconnections.h:314 | Cannot remove node 0: does not exist
2020-02-03T11:26:31.146994Z -36.069 [info ] p/CCF/src/consensus/raft/raft.h:1210 | Removed node 0
2020-02-03T11:29:27.269082Z -42.364 [info ] mp/CCF/src/consensus/raft/raft.h:664 | Deserialising signature at 15
2020-02-03T11:29:27.807006Z        [fail ] p/CCF/src/host/nodeconnections.h:314 | Cannot remove node 0: does not exist

iqsarv avatar Feb 03 '20 11:02 iqsarv

From the error message on the new joining node, it seems that the conflicting node is actually node 3 ({"error":{"code":-32602,"message":"[INVALID_PARAMS]: A node with the same node host ccf-0.ccf.default.svc.cluster.local and port 3100 already exists (node id: 3)"}). However, the memberclient command shows that you are retiring --node-id 0.

Would you mind letting up is the configuration of your network before retiring node 0? You should be able to run the getNetworkInfo RPC to find out which nodes have joined your network.

jumaffre avatar Feb 03 '20 12:02 jumaffre

Seems like a race condition between retire_node and leader election in my script.

There was no primary when the script called retired. Closing this issue for now. Will reopen if the issue reappears

iqsarv avatar Feb 03 '20 17:02 iqsarv

I hit a scenario where there could be two nodes with same hostname:port

root@ccf-1:/opt/azure/ccf# ./client --rpc-address=ccf-2.ccf.default.svc.cluster.local:3200  --ca=network_cert.pem --cert user1_cert.pem --pk user1_privk.pem [email protected]  --pretty-print
Sending RPC to ccf-2.ccf.default.svc.cluster.local:3200
{ 
  "commit": 20,
  "global_commit": 20,
  "id": 0,
  "jsonrpc": "2.0",
  "result": {
    "nodes": [
      { 
        "host": "ccf-0.ccf.default.svc.cluster.local",
        "node_id": 0,
        "port": "3200"
      },
      { 
        "host": "ccf-1.ccf.default.svc.cluster.local",
        "node_id": 1,
        "port": "3200"
      },
      { 
        "host": "ccf-2.ccf.default.svc.cluster.local",
        "node_id": 2,
        "port": "3200"
      },
      { 
        "host": "ccf-0.ccf.default.svc.cluster.local",
        "node_id": 3,
        "port": "3200"
      }
    ],
    "primary_id": 2
  },
  "term": 4
}
  1. Node n0, n1, n2 formed network
  2. Node n0(leader) crashed 2.1 New leader n2 is elected
  3. Node n0 is retired
  4. Node n3 joined with same hostname:port
  5. trust_node n0 is called
  6. Node n3 is continously printing
2020-02-04T09:12:26.493429Z -306.708 [fail ] mp/CCF/src/consensus/raft/raft.h:508 | Invalid authenticated node2node message from node 2 (size: 0)
2020-02-04T09:12:27.211170Z -306.759 [fail ] mp/CCF/src/consensus/raft/raft.h:508 | Invalid authenticated node2node message from node 2 (size: 0)
2020-02-04T09:12:27.574932Z -306.786 [fail ] mp/CCF/src/consensus/raft/raft.h:508 | Invalid authenticated node2node message from node 2 (size: 0)
2020-02-04T09:12:28.610340Z -306.774 [fail ] mp/CCF/src/consensus/raft/raft.h:508 | Invalid authenticated node2node message from node 2 (size: 0)
2020-02-04T09:12:28.606932Z -306.810 [fail ] mp/CCF/src/consensus/raft/raft.h:508 | Invalid authenticated node2node message from node 2 (size: 0)
2020-02-04T09:12:29.146926Z -306.816 [fail ] mp/CCF/src/consensus/raft/raft.h:508 | Invalid authenticated node2node message from node 2 (size: 0)
2020-02-04T09:12:29.686929Z -306.848 [fail ] mp/CCF/src/consensus/raft/raft.h:508 | Invalid authenticated node2node message from node 2 (size: 0)
  1. If retire_n0 is called, the messages stop

trust_node is adding an entry in the Nodes tables irrespective of whether the node is present or not.

Few suggestions:

  1. Should node_id be a key? can we instead have hostname:port as the key for Nodes table?
  2. trust_node should only put if the node entry is present (as a node entry is added as pending initially during start/join)

iqsarv avatar Feb 04 '20 09:02 iqsarv

@iqsarv Thanks for reporting this.

  • It seems that CCF does not currently check whether a node is already retired when trust_node is called. This is why you can run trust_node n0 (step 5.) on a node that was already retired.
  • At which point did you run the getNetworkInfo command? I assume it was after step 5. but before step 7.?
  • At the moment, we use each node id to identify each node. Would it be more convenient for you to use the hostname:port or something that is necessary to deploy CCF nodes with k8s?

jumaffre avatar Feb 04 '20 10:02 jumaffre

@jumaffre You are right, I ran getNetworkInfo before step 7.

Yes, it would be more convenient to have --node-address (hostname:port) instead of --node-id to trust or retire

One follow-up question: What is the behaviour when retire_node or trust_node is called during a re-election? Does it block-wait?

iqsarv avatar Feb 04 '20 10:02 iqsarv

So there's an obvious fix to make sure members cannot trust a node that has already been retired. I will issue a PR for this and let you know when this is fixed.

Regarding your follow up question, you also make a very good point. When the leader node crashes, an election will be triggered by the remaining follower nodes after a specific timeout (specified by --raft-election-timeout-ms when starting a node). When that timeout hasn't yet expired, the follower will still believe that the leader is up and running and will try to forward write requests (in your example, retire_node and trust_node) to the now-dead leader. The leader will never respond to the follower and the client connection will hang.

I guess this is what you've experienced and this is an issue we have already identified (https://github.com/microsoft/CCF/issues/486). I can see from your example commands that you pass a very high election timeout (--raft-election-timeout-ms=100000) so elections in your CCF network will take a very long time to complete. Is this intended?

jumaffre avatar Feb 04 '20 13:02 jumaffre

thanks. i kept the election-timeout longer to test with rpc's in between and it is experimental. as u mentioned, the client is actually stuck when there is Write in the tx and not timing out

good to hear that there is an issue tracked for this.

iqsarv avatar Feb 04 '20 13:02 iqsarv

@iqsarv It should now not be possible to trust a retired node, as per #797.

jumaffre avatar Feb 06 '20 08:02 jumaffre

Closing this as the main issue in this ticket is now fixed (#797).

jumaffre avatar Feb 27 '20 12:02 jumaffre