Skip to content

Commit

Permalink
bug: workaround go1.23 regression in goroutine profile
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Aug 30, 2024
1 parent a9fbda1 commit 3b04a23
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fgprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ type profiler struct {
selfFrame *runtime.Frame
}

// nullTerminationWorkaround deals with a regression in go1.23, see:
// - https://github.com/felixge/fgprof/issues/33
// - https://go-review.googlesource.com/c/go/+/609815
var nullTerminationWorkaround = runtime.Version() == "go1.23.0"

// GoroutineProfile returns the stacks of all goroutines currently managed by
// the scheduler. This includes both goroutines that are currently running
// (On-CPU), as well as waiting (Off-CPU).
Expand All @@ -107,6 +112,11 @@ func (p *profiler) GoroutineProfile() []runtime.StackRecord {
// p.stacks dynamically as well, but let's not over-engineer this until we
// understand those cases better.
for {
if nullTerminationWorkaround {
for i := range p.stacks {
p.stacks[i].Stack0 = [32]uintptr{}
}
}
n, ok := runtime.GoroutineProfile(p.stacks)
if !ok {
p.stacks = make([]runtime.StackRecord, int(float64(n)*1.1))
Expand Down

0 comments on commit 3b04a23

Please sign in to comment.