From 1928a9df64fad6aabbcd1dc8415b36c2c63b1bdd Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Wed, 19 Jan 2022 13:18:21 +0100 Subject: [PATCH] add timeouts to net/http serve --- main.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index e664b04..d734a52 100644 --- a/main.go +++ b/main.go @@ -1070,7 +1070,13 @@ func main() { } sockets = append(sockets, sL) go func() { - _ = http.Serve(sL, cors(proxyRouter)) + srv := &http.Server{ + ReadTimeout: 5 * time.Second, + WriteTimeout: 10 * time.Second, + IdleTimeout: 120 * time.Second, + Handler: cors(proxyRouter), + } + _ = srv.Serve(sL) }() } else { log.Infof("Listening on %s:%d", l.Host, l.Port) @@ -1079,7 +1085,13 @@ func main() { log.Fatalf("Failure listing on %s:%d: %v", l.Host, l.Port, err) } go func() { - err = http.Serve(tL, cors(proxyRouter)) + srv := &http.Server{ + ReadTimeout: 5 * time.Second, + WriteTimeout: 10 * time.Second, + IdleTimeout: 120 * time.Second, + Handler: cors(proxyRouter), + } + err = srv.Serve(tL) if err != nil { log.Fatalf("Failure serving on %s:%d: %v", l.Host, l.Port, err) }