pprof profile/symbol/trace stopped working
- Dominant language
- Go
- Stars
- 25.6k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
For the "github.com/kataras/iris/v12/middleware/pprof" middleware,
* `/debug/pprof/profile`
* `/debug/pprof/trace`
* `/debug/pprof/cmdline`
endpoints return 404 Not Found with body `Unknown profile`.
**To Reproduce**
Just include the pprof middleware in the default way:
```
app := iris.New()
app.HandleMany("GET", "/debug/pprof /debug/pprof/{action:path}", pprof.New())
app.Listen(":8080")
```
and then run `curl -v http://localhost:8080/debug/pprof/profile?seconds=1`. It returns
```
< HTTP/1.1 404 Not Found
< Access-Control-Allow-Credentials: true
< Content-Type: text/plain; charset=utf-8
< Vary: Origin
< X-Content-Type-Options: nosniff
< X-Go-Pprof: 1
< Date: Sun, 25 Apr 2021 07:57:21 GMT
< Content-Length: 16
<
Unknown profile
```
**Expected behavior**
The middleware should gather profile info for the given time and return it via the handler
**Screenshots**
**Desktop (please complete the following information):**
- OS: manjaro linux
- Go version: go1.16.3 linux/amd64
**iris.Version**
v12.2.0-alpha2
Please make sure the bug is reproducible over the `master` branch:
```sh
$ cd PROJECT
$ go get -u github.com/kataras/iris/v12@master
$ go run .
```
**Additional context**
Presumably, it was broken in this commit https://github.com/kataras/iris/commit/5e82fa5b893d67135f25fa0d9178add52d8acee7#diff-925b384c2e2dace51b41ffa40443a7871fb4e1e0213a9309c5fb35f919bbd73f
The reason is the insufficient context passing to the `net/http/pprof` handler. From its source code https://golang.org/src/net/http/pprof/pprof.go, it registers the following handlers:
```
func init() {
http.HandleFunc("/debug/pprof/", Index)
http.HandleFunc("/debug/pprof/cmdline", Cmdline)
http.HandleFunc("/debug/pprof/profile", Profile)
http.HandleFunc("/debug/pprof/symbol", Symbol)
http.HandleFunc("/debug/pprof/trace", Trace)
}
```
So `cmdline`, `profile`, `symbol`, and `trace` are handled individually via separate handlers. But from the iris middleware, there is only one entrypoint:
```
if action := ctx.Params().Get("action"); action != "" {
pprof.Handler(action).ServeHTTP(ctx.ResponseWriter(), ctx.Request())
return
}
```
Contributor guide
Assessment
This issue has not been assessed yet.