From 12c118f4bc101efc5171317e0273ad05457386e7 Mon Sep 17 00:00:00 2001 From: Peter Etelej Date: Tue, 6 Mar 2018 19:10:49 +0300 Subject: [PATCH] Set server timeouts Set server timeouts to avoid leaked descriptors on slow or disappearing clients or slow http attacks. Fixes #51 --- cmd/serve.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/serve.go b/cmd/serve.go index b779170..04891a5 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -74,7 +74,13 @@ var ( port, _ := cmd.Flags().GetInt("port") url := fmt.Sprintf(":%d", port) logrus.Infoln("Serve shiori in", url) - logrus.Fatalln(http.ListenAndServe(url, router)) + svr := &http.Server{ + Addr: url, + Handler: router, + ReadTimeout: 10 * time.Second, + WriteTimeout: 20 * time.Second, + } + logrus.Fatalln(svr.ListenAndServe()) }, } )