mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1145 from coreos/fix_panic
raft: node ignores unexpected local messages receiving from network
This commit is contained in:
commit
03152004d7
15
raft/node.go
15
raft/node.go
@ -231,11 +231,20 @@ func (n *node) Tick() {
|
||||
}
|
||||
|
||||
func (n *node) Campaign(ctx context.Context) error {
|
||||
return n.Step(ctx, pb.Message{Type: msgHup})
|
||||
return n.step(ctx, pb.Message{Type: msgHup})
|
||||
}
|
||||
|
||||
func (n *node) Propose(ctx context.Context, data []byte) error {
|
||||
return n.Step(ctx, pb.Message{Type: msgProp, Entries: []pb.Entry{{Data: data}}})
|
||||
return n.step(ctx, pb.Message{Type: msgProp, Entries: []pb.Entry{{Data: data}}})
|
||||
}
|
||||
|
||||
func (n *node) Step(ctx context.Context, m pb.Message) error {
|
||||
// ignore unexpected local messages receiving over network
|
||||
if m.Type == msgHup || m.Type == msgBeat {
|
||||
// TODO: return an error?
|
||||
return nil
|
||||
}
|
||||
return n.step(ctx, m)
|
||||
}
|
||||
|
||||
func (n *node) ProposeConfChange(ctx context.Context, cc pb.ConfChange) error {
|
||||
@ -248,7 +257,7 @@ func (n *node) ProposeConfChange(ctx context.Context, cc pb.ConfChange) error {
|
||||
|
||||
// Step advances the state machine using msgs. The ctx.Err() will be returned,
|
||||
// if any.
|
||||
func (n *node) Step(ctx context.Context, m pb.Message) error {
|
||||
func (n *node) step(ctx context.Context, m pb.Message) error {
|
||||
ch := n.recvc
|
||||
if m.Type == msgProp {
|
||||
ch = n.propc
|
||||
|
@ -18,7 +18,8 @@ func TestNodeStep(t *testing.T) {
|
||||
propc: make(chan raftpb.Message, 1),
|
||||
recvc: make(chan raftpb.Message, 1),
|
||||
}
|
||||
n.Step(context.TODO(), raftpb.Message{Type: int64(i)})
|
||||
msgt := int64(i)
|
||||
n.Step(context.TODO(), raftpb.Message{Type: msgt})
|
||||
// Proposal goes to proc chan. Others go to recvc chan.
|
||||
if int64(i) == msgProp {
|
||||
select {
|
||||
@ -26,6 +27,13 @@ func TestNodeStep(t *testing.T) {
|
||||
default:
|
||||
t.Errorf("%d: cannot receive %s on propc chan", i, mtmap[i])
|
||||
}
|
||||
} else {
|
||||
if msgt == msgBeat || msgt == msgHup {
|
||||
select {
|
||||
case <-n.recvc:
|
||||
t.Errorf("%d: step should ignore msgHub/msgBeat", i, mtmap[i])
|
||||
default:
|
||||
}
|
||||
} else {
|
||||
select {
|
||||
case <-n.recvc:
|
||||
@ -34,6 +42,7 @@ func TestNodeStep(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel and Stop should unblock Step()
|
||||
|
Loading…
x
Reference in New Issue
Block a user