From 594df29dc132c1573dddda3883eb4a31cdd99756 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 26 Apr 2020 13:18:58 +0200 Subject: [PATCH] Explicitly define timeouts for http and https --- boardvoting.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/boardvoting.go b/boardvoting.go index 1bd0cf0..dca1985 100644 --- a/boardvoting.go +++ b/boardvoting.go @@ -846,8 +846,12 @@ func main() { defer stopAll() server := &http.Server{ - Addr: config.HttpsAddress, - TLSConfig: tlsConfig, + Addr: config.HttpsAddress, + TLSConfig: tlsConfig, + IdleTimeout: time.Second * 120, + ReadHeaderTimeout: time.Second * 10, + ReadTimeout: time.Second * 20, + WriteTimeout: time.Second * 60, } server.Handler = csrf.Protect(csrfKey)(http.DefaultServeMux) @@ -856,7 +860,15 @@ func main() { errs := make(chan error, 1) go func() { - if err := http.ListenAndServe(config.HttpsAddress, http.RedirectHandler(config.BaseURL, http.StatusMovedPermanently)); err != nil { + httpRedirector := &http.Server{ + Addr: config.HttpAddress, + Handler: http.RedirectHandler(config.BaseURL, http.StatusMovedPermanently), + IdleTimeout: time.Second * 5, + ReadHeaderTimeout: time.Second * 10, + ReadTimeout: time.Second * 10, + WriteTimeout: time.Second * 60, + } + if err := httpRedirector.ListenAndServe(); err != nil { errs <- err } close(errs)