Browse Source

fix 2 races

boyska 6 years ago
parent
commit
8b861245c0
2 changed files with 6 additions and 4 deletions
  1. 2 1
      liquidsoap/parser.go
  2. 4 3
      liquidsoap/spawn.go

+ 2 - 1
liquidsoap/parser.go

@@ -17,7 +17,7 @@ type Output struct {
 }
 
 // Parse needs a reader of the log, and will produce parsed output
-func Parse(r io.Reader, parsed chan<- Output) {
+func Parse(r io.Reader, parsed chan<- Output, onexit chan interface{}) {
 	scanner := bufio.NewScanner(r)
 	for scanner.Scan() {
 		out, err := outParseLine(scanner.Text())
@@ -25,6 +25,7 @@ func Parse(r io.Reader, parsed chan<- Output) {
 			parsed <- out
 		}
 	}
+	onexit <- struct{}{}
 }
 
 var lineRegex = regexp.MustCompile(`^([0-9]{4}/[0-9]{2}/[0-9]{2}) ([0-9:]{8}) \[([^:\[\]]*):([0-9])\] (.*)$`)

+ 4 - 3
liquidsoap/spawn.go

@@ -35,7 +35,8 @@ func RunLiquidsoap(configfile string, kill <-chan struct{}) (<-chan Output, <-ch
 	if err != nil {
 		return nil, nil, err
 	}
-	go Parse(log, out)
+	endparse := make(chan interface{})
+	go Parse(log, out, endparse)
 	err = cmd.Start()
 	proc := cmd.Process
 	go func() {
@@ -43,8 +44,8 @@ func RunLiquidsoap(configfile string, kill <-chan struct{}) (<-chan Output, <-ch
 		proc.Signal(syscall.SIGINT)
 	}()
 	go func() {
-		defer log.Close()
-		err = cmd.Wait()
+		<-endparse
+		err := cmd.Wait()
 		close(out)
 		if err != nil {
 			exit <- End{Err: err}