-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Description
go version devel +be8a6fd2e3 Wed Dec 7 17:09:37 2016 +0000 darwin/amd64
The go tool pprof command panics when retrieving /debug/pprof/goroutine?debug=0 profiles.
What did you do?
Test cases are adapted from #16892.
main.go:
package main
import (
"net/http"
_ "net/http/pprof"
)
var sink []byte
func main() {
for i := 0; i < 10; i++ {
sink = make([]byte, 1<<20)
}
panic(http.ListenAndServe("127.0.0.1:8080", nil))
}
test.sh:
#!/usr/bin/env bash
go version
go build -o ./server ./main.go
./server &
server="$!"
sleep 1
echo '--- debug=1 ---'
go tool pprof -raw -output=/dev/null 'http://127.0.0.1:8080/debug/pprof/goroutine?debug=1'
echo '--- debug=0 ---'
go tool pprof -raw -output=/dev/null 'http://127.0.0.1:8080/debug/pprof/goroutine?debug=0'
echo '--- end ---'
kill -KILL -- "$server"
rm ./server
What did you expect to see?
To begin, I expected go tool pprof to not panic on any input.
Second of all, I expected the runtime/pprof and net/http/pprof packages to not produce content that would trigger panics in cmd/pprof or github.com/google/pprof.
What did you see instead?
However, cmd/pprof (be8a6fd) and github.com/google/pprof (google/pprof@01ea337) both panic.
Here's the output of the cmd/pprof panic:
$ ./test.sh
go version devel +be8a6fd2e3 Wed Dec 7 17:09:37 2016 +0000 darwin/amd64
--- debug=1 ---
Fetching profile from http://127.0.0.1:8080/debug/pprof/goroutine?debug=1
Saved profile in /Users/rhys/pprof/pprof.127.0.0.1:8080.goroutine.017.pb.gz
Generating report in /dev/null
--- debug=0 ---
Fetching profile from http://127.0.0.1:8080/debug/pprof/goroutine?debug=0
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x118f774]
goroutine 19 [running]:
internal/pprof/profile.(*Profile).preEncode(0xc420184000)
/usr/local/go/src/internal/pprof/profile/encode.go:65 +0xc04
internal/pprof/profile.(*Profile).Write(0xc420184000, 0x1609a40, 0xc42000e048, 0x0, 0x0)
/usr/local/go/src/internal/pprof/profile/profile.go:216 +0x47
cmd/pprof/internal/driver.grabProfile(0xc42007de80, 0x33, 0x0, 0x0, 0x0, 0x0, 0x14622d0, 0x1462978, 0x160ee00, 0xc420077fb0, ...)
/usr/local/go/src/cmd/pprof/internal/driver/driver.go:410 +0xa95
cmd/pprof/internal/driver.PProf.func1(0xc420144260, 0xc420146000, 0x14622d0, 0x1462978, 0x160ee00, 0xc420077fb0, 0x160f700, 0xc4200860b8, 0xc420144228, 0xc420144250, ...)
/usr/local/go/src/cmd/pprof/internal/driver/driver.go:73 +0x102
created by cmd/pprof/internal/driver.PProf
/usr/local/go/src/cmd/pprof/internal/driver/driver.go:81 +0x3bd
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1202292]
goroutine 1 [running]:
cmd/pprof/internal/driver.processFlags(0x0, 0x160f700, 0xc4200860b8, 0xc420146000, 0x14622d0, 0x1462978)
/usr/local/go/src/cmd/pprof/internal/driver/driver.go:794 +0x762
cmd/pprof/internal/driver.PProf(0x1610d20, 0x16964e8, 0x14622d0, 0x1462978, 0x160ee00, 0xc420077fb0, 0x160f700, 0xc4200860b8, 0x0, 0x0, ...)
/usr/local/go/src/cmd/pprof/internal/driver/driver.go:108 +0x559
main.main()
/usr/local/go/src/cmd/pprof/pprof.go:29 +0x14a
--- end ---
./test.sh: line 17: 51773 Killed: 9 ./server
/cc @matloob @rauls5382
Reactions are currently unavailable