From d57dddf555d977447ac9dbc5f2a6c523a147e20a Mon Sep 17 00:00:00 2001 From: Nathan Smith Date: Thu, 20 Jan 2022 09:52:59 -0800 Subject: [PATCH] Add some reasonable timeouts to API server Fixes #336 Signed-off-by: Nathan Smith --- cmd/app/serve.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/app/serve.go b/cmd/app/serve.go index 4f39f8406..62c70a524 100644 --- a/cmd/app/serve.go +++ b/cmd/app/serve.go @@ -22,6 +22,7 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -196,6 +197,12 @@ func runServeCmd(cmd *cobra.Command, args []string) { api := http.Server{ Addr: host + ":" + port, Handler: decorateHandler(api.NewHandler()), + + // Timeouts + ReadTimeout: 60 * time.Second, + ReadHeaderTimeout: 60 * time.Second, + WriteTimeout: 60 * time.Second, + IdleTimeout: 60 * time.Second, } if err := api.ListenAndServe(); err != nil && err != http.ErrServerClosed {