From 434747e0070c35d99aa89a03645d25179d950835 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Sun, 4 Sep 2022 11:47:05 +0200 Subject: [PATCH] Use timeout in lets encrypt http server --- app.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app.go b/app.go index af622c0b..59101be3 100644 --- a/app.go +++ b/app.go @@ -820,10 +820,19 @@ func (h *Headscale) getTLSSettings() (*tls.Config, error) { // Configuration via autocert with HTTP-01. This requires listening on // port 80 for the certificate validation in addition to the headscale // service, which can be configured to run on any other port. + + server := &http.Server{ + Addr: h.cfg.TLS.LetsEncrypt.Listen, + Handler: certManager.HTTPHandler(http.HandlerFunc(h.redirect)), + ReadTimeout: HTTPReadTimeout, + } + + err := server.ListenAndServe() + go func() { log.Fatal(). Caller(). - Err(http.ListenAndServe(h.cfg.TLS.LetsEncrypt.Listen, certManager.HTTPHandler(http.HandlerFunc(h.redirect)))). + Err(err). Msg("failed to set up a HTTP server") }()