Print detected data races to stdout instead of hiding in a file

This commit is contained in:
Jakob Borg 2014-12-03 07:47:40 +01:00
parent 97abdaca5a
commit 919d005550

View File

@ -106,21 +106,27 @@ func (p *syncthingProcess) stop() error {
} }
defer fd.Close() defer fd.Close()
raceCondition := []byte("DATA RACE") raceConditionStart := []byte("WARNING: DATA RACE")
raceConditionSep := []byte("==================")
sc := bufio.NewScanner(fd) sc := bufio.NewScanner(fd)
race := false
for sc.Scan() { for sc.Scan() {
line := sc.Bytes() line := sc.Bytes()
if bytes.Contains(line, raceCondition) { if race {
name := fmt.Sprintf("race-%d.out", time.Now().Unix()) fmt.Printf("%s\n", line)
cp, _ := os.Create(name) if bytes.Contains(line, raceConditionSep) {
fd.Seek(0, os.SEEK_SET) race = false
io.Copy(cp, fd) }
cp.Close() } else if bytes.Contains(line, raceConditionStart) {
fmt.Printf("%s\n", raceConditionSep)
return errors.New("Race condition detected in " + name) fmt.Printf("%s\n", raceConditionStart)
race = true
if err == nil {
err = errors.New("Race condition detected")
}
} }
} }
return nil return err
} }
func (p *syncthingProcess) get(path string) (*http.Response, error) { func (p *syncthingProcess) get(path string) (*http.Response, error) {