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)
This commit is contained in:
Klaus Post 2025-01-06 07:51:54 -08:00 committed by GitHub
parent 43a7402968
commit 4536ecfaa4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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