From ce9bc5cde4267819edabf387b033557352c32766 Mon Sep 17 00:00:00 2001 From: Bob Callaway Date: Wed, 30 Oct 2024 06:03:04 -0400 Subject: [PATCH] add flag for HTTP idle connection timeout value (#1597) * add flag for HTTP idle connection timeout value Signed-off-by: Bob Callaway * leave default behavior as-is Signed-off-by: Bob Callaway * Only update `http.Server.IdleTimeout` when `http_idle_timeout` flag is set --------- Signed-off-by: Bob Callaway Co-authored-by: Roger Ng --- trillian/ctfe/ct_server/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/trillian/ctfe/ct_server/main.go b/trillian/ctfe/ct_server/main.go index 55ef6cc16d..7e724842a5 100644 --- a/trillian/ctfe/ct_server/main.go +++ b/trillian/ctfe/ct_server/main.go @@ -59,6 +59,7 @@ import ( // Global flags that affect all log instances. var ( httpEndpoint = flag.String("http_endpoint", "localhost:6962", "Endpoint for HTTP (host:port)") + httpIdleTimeout = flag.Duration("http_idle_timeout", -1*time.Second, "Timeout after which idle connections will be closed by server") tlsCert = flag.String("tls_certificate", "", "Path to server TLS certificate") tlsKey = flag.String("tls_key", "", "Path to server TLS private key") metricsEndpoint = flag.String("metrics_endpoint", "", "Endpoint for serving metrics; if left empty, metrics will be visible on --http_endpoint") @@ -334,6 +335,10 @@ func main() { } else { srv = http.Server{Addr: *httpEndpoint, Handler: handler} } + if *httpIdleTimeout > 0 { + srv.IdleTimeout = *httpIdleTimeout + } + shutdownWG := new(sync.WaitGroup) go awaitSignal(func() { shutdownWG.Add(1)