Skip to content

Commit edd64fd

Browse files
authored
fix: avoid panic in init godeltaprof/http/pprof for go 1.23 (#119)
* fix: avoid panic in init godeltaprof/http/pprof * simplify: just use "GET " all the time on go 1.22
1 parent 278dd8c commit edd64fd

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

godeltaprof/http/pprof/pprof.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ type deltaProfiler interface {
2121
}
2222

2323
func init() {
24-
http.HandleFunc("/debug/pprof/delta_heap", Heap)
25-
http.HandleFunc("/debug/pprof/delta_block", Block)
26-
http.HandleFunc("/debug/pprof/delta_mutex", Mutex)
24+
prefix := routePrefix()
25+
http.HandleFunc(prefix+"/debug/pprof/delta_heap", Heap)
26+
http.HandleFunc(prefix+"/debug/pprof/delta_block", Block)
27+
http.HandleFunc(prefix+"/debug/pprof/delta_mutex", Mutex)
2728
}
2829

2930
func Heap(w http.ResponseWriter, r *http.Request) {

godeltaprof/http/pprof/pprof_go21.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build !go1.22
2+
3+
package pprof
4+
5+
func routePrefix() string {
6+
return ""
7+
}

godeltaprof/http/pprof/pprof_go22.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build go1.22
2+
3+
package pprof
4+
5+
func routePrefix() string {
6+
// As of go 1.23 we will panic if we don't prefix with "GET "
7+
// https://github.com/golang/go/blob/9fcffc53593c5cd103630d0d24ef8bd91e17246d/src/net/http/pprof/pprof.go#L98-L97
8+
// https://github.com/golang/go/commit/9fcffc53593c5cd103630d0d24ef8bd91e17246d
9+
return "GET "
10+
}

0 commit comments

Comments
 (0)