Skip to content

Commit

Permalink
Merge pull request #2739 from xiang90/fix_wal
Browse files Browse the repository at this point in the history
wal: change io.EOF returned by readFull to io.ErrUnexpectedEOF
  • Loading branch information
xiang90 committed Apr 23, 2015
2 parents 0efcfcb + d1d7fea commit 01d9c9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wal/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func (d *decoder) decode(rec *walpb.Record) error {
}
data := make([]byte, l)
if _, err = io.ReadFull(d.br, data); err != nil {
// ReadFull returns io.EOF only if no bytes were read
// the decoder should treat this as an ErrUnexpectedEOF instead.
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
return err
}
if err := rec.Unmarshal(data); err != nil {
Expand Down
1 change: 1 addition & 0 deletions wal/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestReadRecord(t *testing.T) {
}{
{infoRecord, &walpb.Record{Type: 1, Crc: crc32.Checksum(infoData, crcTable), Data: infoData}, nil},
{[]byte(""), &walpb.Record{}, io.EOF},
{infoRecord[:8], &walpb.Record{}, io.ErrUnexpectedEOF},
{infoRecord[:len(infoRecord)-len(infoData)-8], &walpb.Record{}, io.ErrUnexpectedEOF},
{infoRecord[:len(infoRecord)-len(infoData)], &walpb.Record{}, io.ErrUnexpectedEOF},
{infoRecord[:len(infoRecord)-8], &walpb.Record{}, io.ErrUnexpectedEOF},
Expand Down

0 comments on commit 01d9c9c

Please sign in to comment.