From ca390560f927b9f1b38468ebe2238f96dacf56d3 Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Fri, 20 Feb 2015 14:58:51 -0800 Subject: [PATCH] rafthttp: fix panic on receiving empty ents 2.0 rc may send empty ents. Fix it for backward compatibility. --- rafthttp/entry_reader.go | 4 +++- rafthttp/streamer.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/rafthttp/entry_reader.go b/rafthttp/entry_reader.go index 4c7974234..277b4c604 100644 --- a/rafthttp/entry_reader.go +++ b/rafthttp/entry_reader.go @@ -54,7 +54,9 @@ func (er *entryReader) readEntries() ([]raftpb.Entry, error) { } er.ents.Add() } - er.lastIndex.Set(int64(ents[l-1].Index)) + if l > 0 { + er.lastIndex.Set(int64(ents[l-1].Index)) + } return ents, nil } diff --git a/rafthttp/streamer.go b/rafthttp/streamer.go index 55bbfa8c3..875002dad 100644 --- a/rafthttp/streamer.go +++ b/rafthttp/streamer.go @@ -295,6 +295,9 @@ func (s *streamReader) handle(r io.Reader) { } return } + if len(ents) == 0 { + continue + } // The commit index field in appendEntry message is not recovered. // The follower updates its commit index through heartbeat. msg := raftpb.Message{