Skip to content

Commit

Permalink
fix: avoid panic in init godeltaprof/http/pprof for go 1.23 (#119)
Browse files Browse the repository at this point in the history
* fix: avoid panic in init godeltaprof/http/pprof

* simplify: just use "GET " all the time on go 1.22
  • Loading branch information
korniltsev authored Aug 15, 2024
1 parent 278dd8c commit edd64fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions godeltaprof/http/pprof/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ type deltaProfiler interface {
}

func init() {
http.HandleFunc("/debug/pprof/delta_heap", Heap)
http.HandleFunc("/debug/pprof/delta_block", Block)
http.HandleFunc("/debug/pprof/delta_mutex", Mutex)
prefix := routePrefix()
http.HandleFunc(prefix+"/debug/pprof/delta_heap", Heap)
http.HandleFunc(prefix+"/debug/pprof/delta_block", Block)
http.HandleFunc(prefix+"/debug/pprof/delta_mutex", Mutex)
}

func Heap(w http.ResponseWriter, r *http.Request) {
Expand Down
7 changes: 7 additions & 0 deletions godeltaprof/http/pprof/pprof_go21.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !go1.22

package pprof

func routePrefix() string {
return ""
}
10 changes: 10 additions & 0 deletions godeltaprof/http/pprof/pprof_go22.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build go1.22

package pprof

func routePrefix() string {
// As of go 1.23 we will panic if we don't prefix with "GET "
// https://github.com/golang/go/blob/9fcffc53593c5cd103630d0d24ef8bd91e17246d/src/net/http/pprof/pprof.go#L98-L97
// https://github.com/golang/go/commit/9fcffc53593c5cd103630d0d24ef8bd91e17246d
return "GET "
}

0 comments on commit edd64fd

Please sign in to comment.