From 9f64d6c8b66315fed482871b36f837f442cdba27 Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Thu, 22 Mar 2018 18:38:17 +0300 Subject: [PATCH] Add keep alive fix --- main.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 35c6dd54d31..0df15827d2e 100644 --- a/main.go +++ b/main.go @@ -1185,7 +1185,7 @@ func listen(listener, controlListener net.Listener, err error) { // handle dashboard registration and nonces if available handleDashboardRegistration() - // Use a custom server so we can control keepalives + // Use a custom server so we can control tves if config.Global.HttpServerOptions.OverrideDefaults { mainRouter.SkipClean(config.Global.HttpServerOptions.SkipURLCleaning) @@ -1200,6 +1200,10 @@ func listen(listener, controlListener net.Listener, err error) { Handler: mainHandler{}, } + if config.Global.CloseConnections { + s.SetKeepAlivesEnabled(false) + } + // Accept connections in a new goroutine. go s.Serve(listener) @@ -1214,7 +1218,12 @@ func listen(listener, controlListener net.Listener, err error) { } else { mainLog.Printf("Gateway started (%s)", VERSION) - go http.Serve(listener, mainHandler{}) + s := &http.Server{Handler: mainHandler{}} + if config.Global.CloseConnections { + s.SetKeepAlivesEnabled(false) + } + + go s.Serve(listener) if controlListener != nil { go http.Serve(controlListener, controlRouter) @@ -1252,6 +1261,10 @@ func listen(listener, controlListener net.Listener, err error) { Handler: mainHandler{}, } + if config.Global.CloseConnections { + s.SetKeepAlivesEnabled(false) + } + mainLog.Info("Custom gateway started") go s.Serve(listener) @@ -1266,7 +1279,12 @@ func listen(listener, controlListener net.Listener, err error) { } else { mainLog.Printf("Gateway resumed (%s)", VERSION) - go http.Serve(listener, mainHandler{}) + s := &http.Server{Handler: mainHandler{}} + if config.Global.CloseConnections { + s.SetKeepAlivesEnabled(false) + } + + go s.Serve(listener) if controlListener != nil { mainLog.Info("Control API listener started: ", controlListener, controlRouter)