aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2018-07-12 18:29:05 -0700
committerDan Willemsen <dwillemsen@google.com>2018-07-12 18:37:38 -0700
commit9611199b944e18b6330b8d32e63ac6ac71588d58 (patch)
tree989900f6d82321b1ebc4a0145ca605a6b7ea03f9
parentecc71f8a494e6a01bfc90897cd52e778f719a459 (diff)
downloadbuild_soong-9611199b944e18b6330b8d32e63ac6ac71588d58.tar.gz
build_soong-9611199b944e18b6330b8d32e63ac6ac71588d58.tar.bz2
build_soong-9611199b944e18b6330b8d32e63ac6ac71588d58.zip
Fix race condition and logging
The extra `defer os.Remove(fifo)` was sometimes racing with the next instance of ninja, removing the file in between when it was re-created and used. Since we're always removing the file before creating it, it's safe to just remove that. The error message for this failure wasn't all that good either, so move so use the status Print/Error calls inside the goroutine instead of the logging ones. Test: `build/soong/build_test.bash -only-soong` repeatedly Change-Id: Icfeb6b68802093bd3a07d3e46046ef7d1a89d4a1
-rw-r--r--ui/status/ninja.go16
1 files changed, 7 insertions, 9 deletions
diff --git a/ui/status/ninja.go b/ui/status/ninja.go
index 4cce6815..7d330f9a 100644
--- a/ui/status/ninja.go
+++ b/ui/status/ninja.go
@@ -37,15 +37,13 @@ func NinjaReader(ctx logger.Logger, status ToolStatus, fifo string) {
ctx.Fatalf("Failed to mkfifo(%q): %v", fifo, err)
}
- go ninjaReader(ctx, status, fifo)
+ go ninjaReader(status, fifo)
}
-func ninjaReader(ctx logger.Logger, status ToolStatus, fifo string) {
- defer os.Remove(fifo)
-
+func ninjaReader(status ToolStatus, fifo string) {
f, err := os.Open(fifo)
if err != nil {
- ctx.Fatal("Failed to open fifo:", err)
+ status.Error(fmt.Sprintf("Failed to open fifo:", err))
}
defer f.Close()
@@ -57,7 +55,7 @@ func ninjaReader(ctx logger.Logger, status ToolStatus, fifo string) {
size, err := readVarInt(r)
if err != nil {
if err != io.EOF {
- ctx.Println("Got error reading from ninja:", err)
+ status.Error(fmt.Sprintf("Got error reading from ninja: %s", err))
}
return
}
@@ -66,9 +64,9 @@ func ninjaReader(ctx logger.Logger, status ToolStatus, fifo string) {
_, err = io.ReadFull(r, buf)
if err != nil {
if err == io.EOF {
- ctx.Printf("Missing message of size %d from ninja\n", size)
+ status.Print(fmt.Sprintf("Missing message of size %d from ninja\n", size))
} else {
- ctx.Fatal("Got error reading from ninja:", err)
+ status.Error(fmt.Sprintf("Got error reading from ninja: %s", err))
}
return
}
@@ -76,7 +74,7 @@ func ninjaReader(ctx logger.Logger, status ToolStatus, fifo string) {
msg := &ninja_frontend.Status{}
err = proto.Unmarshal(buf, msg)
if err != nil {
- ctx.Printf("Error reading message from ninja: %v\n", err)
+ status.Print(fmt.Sprintf("Error reading message from ninja: %v", err))
continue
}