Skip to content

Commit 3b04a23

Browse files
committed
bug: workaround go1.23 regression in goroutine profile
See https://go-review.googlesource.com/c/go/+/609815 for details. Fixes #33
1 parent a9fbda1 commit 3b04a23

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fgprof.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ type profiler struct {
8181
selfFrame *runtime.Frame
8282
}
8383

84+
// nullTerminationWorkaround deals with a regression in go1.23, see:
85+
// - https://github.com/felixge/fgprof/issues/33
86+
// - https://go-review.googlesource.com/c/go/+/609815
87+
var nullTerminationWorkaround = runtime.Version() == "go1.23.0"
88+
8489
// GoroutineProfile returns the stacks of all goroutines currently managed by
8590
// the scheduler. This includes both goroutines that are currently running
8691
// (On-CPU), as well as waiting (Off-CPU).
@@ -107,6 +112,11 @@ func (p *profiler) GoroutineProfile() []runtime.StackRecord {
107112
// p.stacks dynamically as well, but let's not over-engineer this until we
108113
// understand those cases better.
109114
for {
115+
if nullTerminationWorkaround {
116+
for i := range p.stacks {
117+
p.stacks[i].Stack0 = [32]uintptr{}
118+
}
119+
}
110120
n, ok := runtime.GoroutineProfile(p.stacks)
111121
if !ok {
112122
p.stacks = make([]runtime.StackRecord, int(float64(n)*1.1))

0 commit comments

Comments
 (0)