diff --git a/consul/server.go b/consul/server.go index cb30d2335a..26fab86fb5 100644 --- a/consul/server.go +++ b/consul/server.go @@ -192,6 +192,16 @@ func (s *Server) setupRaft() error { // Setup the peer store s.raftPeers = raft.NewJSONPeers(path, trans) + // Ensure local host is always included + peers, err := s.raftPeers.Peers() + if err != nil { + store.Close() + return err + } + if !raft.PeerContained(peers, trans.LocalAddr()) { + s.raftPeers.SetPeers(raft.AddUniquePeer(peers, trans.LocalAddr())) + } + // Setup the Raft store s.raft, err = raft.NewRaft(s.config.RaftConfig, s.fsm, store, store, snapshots, s.raftPeers, trans) diff --git a/consul/status_endpoint_test.go b/consul/status_endpoint_test.go index f23bbdeb39..ef029db028 100644 --- a/consul/status_endpoint_test.go +++ b/consul/status_endpoint_test.go @@ -47,3 +47,20 @@ func TestStatusLeader(t *testing.T) { t.Fatalf("no leader") } } + +func TestStatusPeers(t *testing.T) { + dir1, s1 := testServer(t) + defer os.RemoveAll(dir1) + defer s1.Shutdown() + client := rpcClient(t, s1) + defer client.Close() + + arg := struct{}{} + var peers []string + if err := client.Call("Status.Peers", arg, &peers); err != nil { + t.Fatalf("err: %v", err) + } + if len(peers) != 1 { + t.Fatalf("no peers: %v", peers) + } +}