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

Lines changed: 4 additions & 3 deletions
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) {
Lines changed: 7 additions & 0 deletions
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+
}
Lines changed: 10 additions & 0 deletions
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)