diff --git a/cmd/web.go b/cmd/web.go index 6e39db2178..1998ee7668 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()) + 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()) + // 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") - log.Info("Stopped pprof server: %v", http.ListenAndServe("localhost:6060", nil)) + log.Info("Stopped pprof server: %v", http.ListenAndServe("localhost:6060", mux)) finished() }