From 5b5572d74ceb6ed1048de140a4a49f62fa5d99ef Mon Sep 17 00:00:00 2001 From: sentriz Date: Sat, 2 Dec 2023 18:38:42 +0000 Subject: [PATCH] unset http WriteTimeout when -pprof --- cmd/gonic/gonic.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index cf4bd69..ee601b2 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -285,7 +285,17 @@ func main() { })) } + var ( + readTimeout = 5 * time.Second + writeTimeout = 5 * time.Second + idleTimeout = 5 * time.Second + ) + if *confPprof { + // overwrite global WriteTimeout. in future we should set this only for these handlers + // https://github.com/golang/go/issues/62358 + writeTimeout = 0 + mux.HandleFunc("/debug/pprof/", pprof.Index) mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) mux.HandleFunc("/debug/pprof/profile", pprof.Profile) @@ -300,7 +310,7 @@ func main() { server := &http.Server{ Addr: *confListenAddr, - ReadTimeout: 5 * time.Second, WriteTimeout: 5 * time.Second, IdleTimeout: 5 * time.Second, + ReadTimeout: readTimeout, WriteTimeout: writeTimeout, IdleTimeout: idleTimeout, Handler: mux, } errgrp.Go(func() error {