Skip to content

Commit 48fe13f

Browse files
committed
avoid possible nil entry.pb
I0410 15:17:53 72441 volume_layout.go:343] Volume 390 becomes unwritable I0410 15:17:53 72441 volume_layout.go:343] Volume 391 becomes unwritable I0410 15:17:53 72441 volume_layout.go:343] Volume 394 becomes unwritable I0410 15:17:53 72441 volume_layout.go:343] Volume 392 becomes unwritable I0410 15:17:58 72441 volume_layout.go:343] Volume 393 becomes unwritable I0410 15:17:58 72441 volume_layout.go:343] Volume 395 becomes unwritable panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1962c8a] goroutine 68239935 [running]: github.com/chrislusf/raft.(*LogEntry).Term(...) /home/travis/gopath/pkg/mod/github.com/chrislusf/raft@v1.0.4/log_entry.go:59 github.com/chrislusf/raft.(*server).TakeSnapshot(0xc00014f320, 0xc028b5a600, 0xc03995bc00) /home/travis/gopath/pkg/mod/github.com/chrislusf/raft@v1.0.4/server.go:1276 +0x50a github.com/chrislusf/raft.(*server).maybeTakeSnapshot.func1(0xc00014f320) /home/travis/gopath/pkg/mod/github.com/chrislusf/raft@v1.0.4/server.go:1221 +0x5b created by github.com/chrislusf/raft.(*server).maybeTakeSnapshot /home/travis/gopath/pkg/mod/github.com/chrislusf/raft@v1.0.4/server.go:1219 +0x98
1 parent a018168 commit 48fe13f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,8 +1273,11 @@ func (s *server) TakeSnapshot() error {
12731273
// We do not want to send the whole snapshot to the slightly slow machines
12741274
if lastIndex-s.log.startIndex > NumberOfLogEntriesAfterSnapshot {
12751275
compactIndex := lastIndex - NumberOfLogEntriesAfterSnapshot
1276-
compactTerm := s.log.getEntry(compactIndex).Term()
1277-
s.log.compact(compactIndex, compactTerm)
1276+
entry := s.log.getEntry(compactIndex)
1277+
if entry.pb != nil {
1278+
compactTerm := entry.Term()
1279+
s.log.compact(compactIndex, compactTerm)
1280+
}
12781281
}
12791282

12801283
return nil

0 commit comments

Comments
 (0)