Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/pprof: panic on debug=0 goroutine profiles #18229

Closed
rhysh opened this issue Dec 7, 2016 · 2 comments
Closed

cmd/pprof: panic on debug=0 goroutine profiles #18229

rhysh opened this issue Dec 7, 2016 · 2 comments

Comments

@rhysh
Copy link
Contributor

rhysh commented Dec 7, 2016

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

@rauls5382
Copy link
Contributor

The profile generated is invalid as it has locations with id = 0, eg:

sample: [
location_id: [ 0x0000000000000000 ]
value : [ 1 ]
} # sample[1]

@gopherbot
Copy link

CL https://golang.org/cl/34028 mentions this issue.

@golang golang locked and limited conversation to collaborators Dec 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants