diff --git a/tools/replay/main.go b/tools/replay/main.go index ec5dcfbef..608c4635c 100644 --- a/tools/replay/main.go +++ b/tools/replay/main.go @@ -4,6 +4,7 @@ import ( "context" "flag" "fmt" + "log" "math" "os" "sync" @@ -86,7 +87,7 @@ func NewClient(w *FileWorker) *ClientWorker { func (w *FileWorker) Run(file string, wg *sync.WaitGroup) { clients := make(map[uint32]*ClientWorker, 0) - parseRecords(file, func(r Record) bool { + err := parseRecords(file, func(r Record) bool { client, ok := clients[r.Client] if !ok { client = NewClient(w) @@ -98,6 +99,10 @@ func (w *FileWorker) Run(file string, wg *sync.WaitGroup) { return true }) + if err != nil { + log.Fatalf("Could not parse records!") + } + for _, client := range clients { close(client.incoming) } diff --git a/tools/replay/parsing.go b/tools/replay/parsing.go index 7dc260fdf..7d8021e33 100644 --- a/tools/replay/parsing.go +++ b/tools/replay/parsing.go @@ -3,7 +3,9 @@ package main import ( "bufio" "encoding/binary" + "errors" "io" + "log" "os" ) @@ -33,6 +35,14 @@ func parseStrings(file io.Reader) (out []interface{}, err error) { if err != nil { return nil, err } + + if strLen > 100000000 { + log.Printf("Bad string length %v, index %v out of %v", strLen, i, num) + for j := 0; j < i; j++ { + log.Printf("Str %v %v", j, out[j]) + } + return nil, errors.New("failed to parse a string len ") + } out[i] = kBigEmptyBytes[:strLen] continue } @@ -56,6 +66,7 @@ func parseRecords(filename string, cb func(Record) bool) error { defer file.Close() reader := bufio.NewReader(file) + recordNum := 0 for { var rec Record err := binary.Read(reader, binary.LittleEndian, &rec.RecordHeader) @@ -68,12 +79,14 @@ func parseRecords(filename string, cb func(Record) bool) error { rec.values, err = parseStrings(reader) if err != nil { + log.Printf("Could not parse %vth record", recordNum) return err } if !cb(rec) { return nil } + recordNum++ } return nil