Golang - net / http / pprof not working

I have a http client service:

s := &http.Server{ Addr: config.Port, Handler: Controller.Log(http.DefaultServeMux), ReadTimeout: 3 * time.Second, WriteTimeout: 3 * time.Second, } http.HandleFunc("/exapmle/router/", exampleFunc) err := s.ListenAndServe() if err != nil { log.Critical(err) os.Exit(1) } 

Does not work:

 go tool pprof http://localhost:8201/debug/pprof/profile 

Return Error:

 Failed to fetch http://localhost:8201/debug/pprof/profile?seconds=30 

Thanks.

edit: I think the problem is that I am rewriting the default HTTP server, the net / http / pprof package introduce the http handler:

 func init() { http.Handle("/debug/pprof/", http.HandlerFunc(Index)) http.Handle("/debug/pprof/cmdline", http.HandlerFunc(Cmdline)) http.Handle("/debug/pprof/profile", http.HandlerFunc(Profile)) http.Handle("/debug/pprof/symbol", http.HandlerFunc(Symbol)) } 

the handler does not work in my code.

+6
source share
1 answer

You set "WriteTimeout" less time to write a profile.

on pprof.StartCPUProfile () to execute, it is already starting to write, see:

Thus, http.WriteTimeout should be longer than the profile write time.

Sorry for the bad english.

+9
source

All Articles