From fbab94d22019a4c49b7e475ed627f2cbff0d9df6 Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-boundary <82989682+hc-github-team-secure-boundary@users.noreply.github.com> Date: Wed, 11 Feb 2026 10:43:53 -0500 Subject: [PATCH] Backport of chore: pprof build updates into release/0.21.x (#6424) * backport of commit ef166d3bc13185fc1ba5d94cb5f2ac8550f03c41 * backport of commit 05d885efc6f209baf51c1a19e4d4255d8c74c251 --------- Co-authored-by: Michael Li --- Makefile | 1 + internal/cmd/base/pprof_on.go | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index bc67c9ac33..046425388a 100644 --- a/Makefile +++ b/Makefile @@ -68,6 +68,7 @@ install-no-plugins: install .PHONY: build-pprof build-pprof: BUILD_TAGS+=pprof +build-pprof: BUILD_TAGS+=ui build-pprof: @echo "==> Building Boundary with memory pprof enabled" @CGO_ENABLED=$(CGO_ENABLED) BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/build.sh'" diff --git a/internal/cmd/base/pprof_on.go b/internal/cmd/base/pprof_on.go index 7c12a47e65..3a23395fdf 100644 --- a/internal/cmd/base/pprof_on.go +++ b/internal/cmd/base/pprof_on.go @@ -10,18 +10,29 @@ import ( "context" "errors" "net/http" + "net/http/pprof" "github.com/hashicorp/boundary/internal/event" - - _ "net/http/pprof" ) func StartPprof(ctx context.Context) { const op = "base.StartPprof" go func() { const addr = "localhost:6060" + mux := http.NewServeMux() + mux.HandleFunc("/debug/pprof/", pprof.Index) + mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + mux.HandleFunc("/debug/pprof/profile", pprof.Profile) + mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + mux.HandleFunc("/debug/pprof/trace", pprof.Trace) + mux.Handle("/debug/pprof/block", pprof.Handler("block")) + mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine")) + mux.Handle("/debug/pprof/heap", pprof.Handler("heap")) + mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate")) + mux.Handle("/debug/pprof/mutex", pprof.Handler("mutex")) + mux.Handle("/debug/pprof/allocs", pprof.Handler("allocs")) event.WriteSysEvent(ctx, op, "starting pprof HTTP server", "addr", addr) - if err := http.ListenAndServe(addr, nil); err != nil && !errors.Is(err, http.ErrServerClosed) { + if err := http.ListenAndServe(addr, mux); err != nil && !errors.Is(err, http.ErrServerClosed) { event.WriteSysEvent(ctx, op, "failed to serve pprof HTTP server", "error", err.Error()) } }()