From f5b4c09c80866c9f69ed059576c5fbac37a3a6c5 Mon Sep 17 00:00:00 2001 From: Richard Mitchell <richard.j.mitchell@gmail.com> Date: Sun, 5 Aug 2018 12:11:33 +0100 Subject: [PATCH] Set timeouts on the HTTP server. --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 014d333..3f07484 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "log" "net/http" "os" + "time" "gopkg.in/alecthomas/kingpin.v2" "gopkg.in/yaml.v2" @@ -64,7 +65,12 @@ func runServer() { prometheus.MustRegister(NewSensorCollector(namespace, bridge, cfg.SensorConfig.IgnoreTypes)) http.Handle("/metrics", promhttp.Handler()) - log.Fatal(http.ListenAndServe((*addr).String(), nil)) + srv := &http.Server{ + Addr: (*addr).String(), + ReadTimeout: 5 * time.Second, + WriteTimeout: 10 * time.Second, + } + log.Fatal(srv.ListenAndServe()) } func main() { -- GitLab