From 161b1a67708913138f203ca98bf50d5f7e62cf55 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Thu, 1 Jan 2026 12:19:48 +0800 Subject: [PATCH 1/2] refactor(pprof): use explicit mux instead of DefaultServeMux - Replace blank import of net/http/pprof with explicit import - Create dedicated http.ServeMux for pprof server - Register pprof handlers explicitly - Improves isolation and maintainability Signed-off-by: luojiyin --- cmd/web.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/web.go b/cmd/web.go index 6e39db2178da0..2e9a5d240035f 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -8,14 +8,13 @@ import ( "fmt" "net" "net/http" + "net/http/pprof" "os" "path/filepath" "strconv" "strings" "time" - _ "net/http/pprof" // Used for debugging if enabled and a web server is running - "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/gtprof" @@ -234,12 +233,18 @@ func serveInstalled(c *cli.Command) error { } func servePprof() { - // FIXME: it shouldn't use the global DefaultServeMux, and it should use a proper context - http.DefaultServeMux.Handle("/debug/fgprof", fgprof.Handler()) + // FIXME: it should use a proper context + mux := http.NewServeMux() + mux.HandleFunc("/debug/pprof/", pprof.Index) + mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + mux.HandleFunc("/debug/pprof/profile", pprof.Profile) + mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + mux.HandleFunc("/debug/pprof/trace", pprof.Trace) + mux.Handle("/debug/fgprof", fgprof.Handler()) _, _, finished := process.GetManager().AddTypedContext(context.TODO(), "Web: PProf Server", process.SystemProcessType, true) // The pprof server is for debug purpose only, it shouldn't be exposed on public network. At the moment, it's not worth introducing a configurable option for it. log.Info("Starting pprof server on localhost:6060") - log.Info("Stopped pprof server: %v", http.ListenAndServe("localhost:6060", nil)) + log.Info("Stopped pprof server: %v", http.ListenAndServe("localhost:6060", mux)) finished() } From fee7c12238ea43c3d6d77f7c71c998dad348f1e7 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 2 Jan 2026 15:17:43 +0800 Subject: [PATCH 2/2] Update web.go Signed-off-by: wxiaoguang --- cmd/web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/web.go b/cmd/web.go index 2e9a5d240035f..1998ee76688d1 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -233,7 +233,6 @@ func serveInstalled(c *cli.Command) error { } func servePprof() { - // FIXME: it should use a proper context mux := http.NewServeMux() mux.HandleFunc("/debug/pprof/", pprof.Index) mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) @@ -241,6 +240,7 @@ func servePprof() { mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) mux.HandleFunc("/debug/pprof/trace", pprof.Trace) mux.Handle("/debug/fgprof", fgprof.Handler()) + // FIXME: it should use a proper context _, _, finished := process.GetManager().AddTypedContext(context.TODO(), "Web: PProf Server", process.SystemProcessType, true) // The pprof server is for debug purpose only, it shouldn't be exposed on public network. At the moment, it's not worth introducing a configurable option for it. log.Info("Starting pprof server on localhost:6060")