Skip to content

Commit

Permalink
Add default server http server timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
edgard committed Aug 5, 2019
1 parent 0704ce7 commit a8ec208
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions iperf3_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())
}

0 comments on commit a8ec208

Please sign in to comment.