Skip to content

Commit bdc7803

Browse files
authoredJul 24, 2023
fix: go 1.21 adding goroutine ID to creator+location (#685)
tested on go1.21rc2 as of today's latest
1 parent 66bcd9d commit bdc7803

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
 

‎gleak/goroutine/goroutine.go

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
// - "copystack"
3434
// - "preempted"
3535
// - ("???" ... something IS severely broken.)
36+
//
3637
// In case a goroutine is in waiting state, the State field instead starts with
3738
// one of the following strings, never showing a lonely "waiting" string, but
3839
// rather one of the reasons for waiting:
@@ -176,6 +177,9 @@ func findCreator(backtrace string) (creator, location string) {
176177
}
177178
location = strings.TrimSpace(details[1][:offsetpos])
178179
creator = details[0]
180+
if offsetpos := strings.LastIndex(creator, " in goroutine "); offsetpos >= 0 {
181+
creator = creator[:offsetpos]
182+
}
179183
return
180184
}
181185

‎gleak/ignoring_creator_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ var _ = Describe("IgnoringCreator matcher", func() {
2727
It("matches a creator function by full name", func() {
2828
type T struct{}
2929
pkg := reflect.TypeOf(T{}).PkgPath()
30-
m := IgnoringCreator(pkg + ".creator")
30+
ignore := pkg + ".creator"
31+
m := IgnoringCreator(ignore)
3132
g := creator()
32-
Expect(m.Match(g)).To(BeTrue(), "creator %v", g.String())
33+
Expect(m.Match(g)).To(BeTrue(), "creator: %v\ntried to ignore: %s",
34+
g.String(), ignore)
3335
Expect(m.Match(goroutine.Current())).To(BeFalse())
3436
})
3537

0 commit comments

Comments
 (0)
Please sign in to comment.