Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodes try to self connect when given predefined config #6

Open
alexanderturner opened this issue Jul 27, 2022 · 1 comment
Open

Nodes try to self connect when given predefined config #6

alexanderturner opened this issue Jul 27, 2022 · 1 comment

Comments

@alexanderturner
Copy link

alexanderturner commented Jul 27, 2022

Hi there and thanks for sharing this project. I'm keen to introduce Raft into one of my projects in which there is a predefined cluster. During boot I'm getting the follower error on 2 of the three nodes:

panic: raft.membership: attempted to send msg to local member; should never happen

Here is the relevant code

func raftInit() {
	raftgrpc.Register(
		raftgrpc.WithDialOptions(grpc.WithInsecure()),
	)
	fsm = newstateMachine()
	node = raft.NewNode(fsm, transport.GRPC)
	raftServer = grpc.NewServer()
	raftgrpc.RegisterHandler(raftServer, node.Handler())

	m1 := raft.RawMember{ID: 1, Address: "host1:8081"}
	m2 := raft.RawMember{ID: 2, Address: "host2:8081"}
	m3 := raft.RawMember{ID: 3, Address: "host3:8081"}

	go func() {
		lis, err := net.Listen("tcp", ":8081")
		if err != nil {
			log.Fatal(err)
		}

		err = raftServer.Serve(lis)
		if err != nil {
			log.Fatal(err)
		}
	}()

  go func() {
	err := node.Start(raft.WithInitCluster(), raft.WithMembers(m1, m2, m3) )
                 if err != nil {
			log.Fatal(err)
		}
	}()
}

Not sure if this is misconfigured on my side or if there's an issue here. Would greatly appreciate you assistance.

@shaj13
Copy link
Owner

shaj13 commented Sep 9, 2022

@alexanderturner Unable to reproduce the issue from the given code, do you use the same WithMembers configuration with all hosts?

Docs:

WithMembers add the given members to the raft node.

WithMembers safe to be used with initiate cluster kind options, ("WithForceNewCluster", "WithRestore", "WithInitCluster") Otherwise, it may conflicts with other options like WithJoin.

As long as only one url member, WithMembers will only set the current node, then it will be safe to be composed with other options even "WithJoin".

WithMembers and WithInitCluster must be applied to all cluster nodes when they are composed, Otherwise, the quorum will be lost and the cluster become unavailable.

Node A:
n.Start(WithInitCluster(), WithMembers(<node A>, <node B>))

Node B:
n.Start(WithInitCluster(), WithMembers(<node B>, <node A>))
Note: the first member will be assigned to the current node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants