Merge pull request #18651 from roidelapluie/roidelapluie/fgprof-concurrency-limit

web: reject concurrent fgprof profiles with 500, aligning with pprof
This commit is contained in:
Julien 2026-05-08 18:12:46 +02:00 committed by GitHub
commit ecab2f45a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -114,7 +114,10 @@ const (
Stopping
)
var fgprofHandler = fgprof.Handler()
var (
fgprofHandler = fgprof.Handler()
fgprofMu sync.Mutex
)
// withStackTracer logs the stack trace in case the request panics. The function
// will re-raise the error which will then be handled by the net/http package.
@ -636,6 +639,11 @@ func serveDebug(w http.ResponseWriter, req *http.Request) {
case "trace":
pprof.Trace(w, req)
case "fgprof":
if !fgprofMu.TryLock() {
http.Error(w, "Could not enable fgprof profiling: fgprof profiling already in use", http.StatusInternalServerError)
return
}
defer fgprofMu.Unlock()
fgprofHandler.ServeHTTP(w, req)
default:
req.URL.Path = "/debug/pprof/" + subpath