From 4536ecfaa4d81dd3f648616094a4936162089db8 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Mon, 6 Jan 2025 07:51:54 -0800 Subject: [PATCH] Add cpuio profiling potential crash workaround (#20809) Add profiling potential crash wourkaround Using admin traces could potentially crash the server (or handler more likely) due to upstream divide by 0: https://github.com/felixge/fgprof/pull/34 Ensure the profile always runs 100ms before stopping, so sample count isn't 0 (default sample rate ~10ms/sample, but allow for cpu starvation) --- cmd/utils.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/utils.go b/cmd/utils.go index 87926b93d..be3a9c55e 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -411,7 +411,12 @@ func startProfiler(profilerType string) (minioProfiler, error) { return nil, err } stop := fgprof.Start(f, fgprof.FormatPprof) + startedAt := time.Now() prof.stopFn = func() ([]byte, error) { + if elapsed := time.Since(startedAt); elapsed < 100*time.Millisecond { + // Light hack around https://github.com/felixge/fgprof/pull/34 + time.Sleep(100*time.Millisecond - elapsed) + } err := stop() if err != nil { return nil, err