diff --git a/app/api_topology.go b/app/api_topology.go index 7431ff3113..653862de11 100644 --- a/app/api_topology.go +++ b/app/api_topology.go @@ -59,7 +59,10 @@ func makeTopologyHandlers( // Websocket for the full topology. This route overlaps with the next. get.HandleFunc(base+"/ws", func(w http.ResponseWriter, r *http.Request) { - r.ParseForm() + if err := r.ParseForm(); err != nil { + respondWith(w, http.StatusInternalServerError, err.Error()) + return + } loop := websocketLoop if t := r.Form.Get("t"); t != "" { var err error @@ -140,7 +143,9 @@ func handleWebsocket( diff := report.TopoDiff(previousTopo, newTopo) previousTopo = newTopo - conn.SetWriteDeadline(time.Now().Add(websocketTimeout)) + if err := conn.SetWriteDeadline(time.Now().Add(websocketTimeout)); err != nil { + return + } if err := conn.WriteJSON(diff); err != nil { return } diff --git a/app/main.go b/app/main.go index 553cd174a3..4c8bdf0378 100644 --- a/app/main.go +++ b/app/main.go @@ -3,7 +3,6 @@ package main import ( "flag" "fmt" - "io/ioutil" "log" "log/syslog" "net/http" @@ -28,7 +27,6 @@ func main() { probes = flag.String("probes", strings.Join(defaultProbes, ","), "list of probe endpoints, comma separated") batch = flag.Duration("batch", 1*time.Second, "batch interval") window = flag.Duration("window", 15*time.Second, "window") - pidfile = flag.String("pidfile", "", "write PID file") listen = flag.String("http.address", ":"+strconv.Itoa(xfer.AppPort), "webserver listen address") ) flag.Parse() @@ -57,15 +55,6 @@ func main() { log.SetOutput(f) } - if *pidfile != "" { - err := ioutil.WriteFile(*pidfile, []byte(fmt.Sprint(os.Getpid())), 0644) - if err != nil { - log.Print(err) - return - } - defer os.Remove(*pidfile) - } - log.Printf("app starting, version %s", version) // Collector deals with the probes, and generates merged reports. diff --git a/app/server_helpers.go b/app/server_helpers.go index ceb7540f28..8aa1fe8285 100644 --- a/app/server_helpers.go +++ b/app/server_helpers.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "log" "net/http" ) @@ -9,5 +10,7 @@ func respondWith(w http.ResponseWriter, code int, response interface{}) { w.Header().Set("Content-Type", "application/json") w.Header().Add("Cache-Control", "no-cache") w.WriteHeader(code) - json.NewEncoder(w).Encode(response) + if err := json.NewEncoder(w).Encode(response); err != nil { + log.Print(err) + } } diff --git a/experimental/example/goapp/app.go b/experimental/example/goapp/app.go index fb30a15e01..a184b45b90 100644 --- a/experimental/example/goapp/app.go +++ b/experimental/example/goapp/app.go @@ -82,9 +82,12 @@ func get(target string) { log.Printf("%s: %v", target, err) return } + defer resp.Body.Close() log.Printf("%s: %s", target, resp.Status) - io.Copy(ioutil.Discard, resp.Body) - resp.Body.Close() + if _, err := io.Copy(ioutil.Discard, resp.Body); err != nil { + log.Printf("%s: %v", target, err) + return + } } func interrupt() error { diff --git a/experimental/genreport/main.go b/experimental/genreport/main.go index 22ea22ba90..51875f6cce 100644 --- a/experimental/genreport/main.go +++ b/experimental/genreport/main.go @@ -3,11 +3,14 @@ package main import ( "encoding/json" "flag" + "log" "os" ) func main() { nodes := flag.Int("nodes", 10, "node count") flag.Parse() - json.NewEncoder(os.Stdout).Encode(DemoReport(*nodes)) + if err := json.NewEncoder(os.Stdout).Encode(DemoReport(*nodes)); err != nil { + log.Print(err) + } } diff --git a/probe/main.go b/probe/main.go index f2bf1ffc26..dacc1db436 100644 --- a/probe/main.go +++ b/probe/main.go @@ -53,7 +53,7 @@ func main() { log.Printf("exposing Prometheus endpoint at %s%s", *httpListen, *prometheusEndpoint) http.Handle(*prometheusEndpoint, makePrometheusHandler()) } - go http.ListenAndServe(*httpListen, nil) + go func(err error) { log.Print(err) }(http.ListenAndServe(*httpListen, nil)) } if *spyProcs && os.Getegid() != 0 { diff --git a/probe/process_mapper_test.go b/probe/process_mapper_test.go index 61f9694280..99421a9fc5 100644 --- a/probe/process_mapper_test.go +++ b/probe/process_mapper_test.go @@ -17,7 +17,7 @@ func TestCgroupMapper(t *testing.T) { "/netscape/notify_on_release": "0\n", "/weirdfile": "", }) - defer os.RemoveAll(tmp) + defer removeAll(t, tmp) m := newCgroupMapper(tmp, 1*time.Second) for pid, want := range map[uint]string{ @@ -44,14 +44,20 @@ func setupTmpFS(t *testing.T, fs map[string]string) string { for file, content := range fs { dir := path.Dir(file) if err := os.MkdirAll(filepath.Join(tmp, dir), 0777); err != nil { - os.RemoveAll(tmp) + removeAll(t, tmp) t.Fatalf("MkdirAll: %v", err) } if err := ioutil.WriteFile(filepath.Join(tmp, file), []byte(content), 0655); err != nil { - os.RemoveAll(tmp) + removeAll(t, tmp) t.Fatalf("WriteFile: %v", err) } } return tmp } + +func removeAll(t *testing.T, path string) { + if err := os.RemoveAll(path); err != nil { + t.Error(err) + } +}