From a8ec208d976e4cce03277398c93d8bcf5f38efd4 Mon Sep 17 00:00:00 2001 From: Edgard Castro Date: Mon, 5 Aug 2019 02:17:22 +0200 Subject: [PATCH] Add default server http server timeout --- iperf3_exporter.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/iperf3_exporter.go b/iperf3_exporter.go index 1a2059f..af732d4 100644 --- a/iperf3_exporter.go +++ b/iperf3_exporter.go @@ -172,6 +172,11 @@ func handler(w http.ResponseWriter, r *http.Request) { timeoutSeconds = 30 } } + + if timeoutSeconds > 30 { + timeoutSeconds = 30 + } + runTimeout := time.Duration(timeoutSeconds * float64(time.Second)) start := time.Now() @@ -217,6 +222,12 @@ func main() { } }) - log.Infof("Listening on %s", *listenAddress) - log.Fatal(http.ListenAndServe(*listenAddress, nil)) + srv := &http.Server{ + Addr: *listenAddress, + ReadTimeout: 60 * time.Second, + WriteTimeout: 60 * time.Second, + } + + log.Infof("Listening on %s", srv.Addr) + log.Fatal(srv.ListenAndServe()) }