浏览代码

rafthttp: fix panic on receiving empty ents

2.0 rc may send empty ents. Fix it for backward compatibility.
Yicheng Qin 11 年之前
父节点
当前提交
ca390560f9
共有 2 个文件被更改,包括 6 次插入1 次删除
  1. 3 1
      rafthttp/entry_reader.go
  2. 3 0
      rafthttp/streamer.go

+ 3 - 1
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
 }
 

+ 3 - 0
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{