Skip to content

Commit ecab2f4

Browse files
authored
Merge pull request prometheus#18651 from roidelapluie/roidelapluie/fgprof-concurrency-limit
web: reject concurrent fgprof profiles with 500, aligning with pprof
2 parents db0c414 + dd54642 commit ecab2f4

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

web/web.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ const (
114114
Stopping
115115
)
116116

117-
var fgprofHandler = fgprof.Handler()
117+
var (
118+
fgprofHandler = fgprof.Handler()
119+
fgprofMu sync.Mutex
120+
)
118121

119122
// withStackTracer logs the stack trace in case the request panics. The function
120123
// 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) {
636639
case "trace":
637640
pprof.Trace(w, req)
638641
case "fgprof":
642+
if !fgprofMu.TryLock() {
643+
http.Error(w, "Could not enable fgprof profiling: fgprof profiling already in use", http.StatusInternalServerError)
644+
return
645+
}
646+
defer fgprofMu.Unlock()
639647
fgprofHandler.ServeHTTP(w, req)
640648
default:
641649
req.URL.Path = "/debug/pprof/" + subpath

0 commit comments

Comments
 (0)