Skip to content

Commit

Permalink
fix: go 1.21 adding goroutine ID to creator+location (#685)
Browse files Browse the repository at this point in the history
tested on go1.21rc2 as of today's latest
  • Loading branch information
thediveo authored Jul 24, 2023
1 parent 66bcd9d commit bdc7803
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions gleak/goroutine/goroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
// - "copystack"
// - "preempted"
// - ("???" ... something IS severely broken.)
//
// In case a goroutine is in waiting state, the State field instead starts with
// one of the following strings, never showing a lonely "waiting" string, but
// rather one of the reasons for waiting:
Expand Down Expand Up @@ -176,6 +177,9 @@ func findCreator(backtrace string) (creator, location string) {
}
location = strings.TrimSpace(details[1][:offsetpos])
creator = details[0]
if offsetpos := strings.LastIndex(creator, " in goroutine "); offsetpos >= 0 {
creator = creator[:offsetpos]
}
return
}

Expand Down
6 changes: 4 additions & 2 deletions gleak/ignoring_creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ var _ = Describe("IgnoringCreator matcher", func() {
It("matches a creator function by full name", func() {
type T struct{}
pkg := reflect.TypeOf(T{}).PkgPath()
m := IgnoringCreator(pkg + ".creator")
ignore := pkg + ".creator"
m := IgnoringCreator(ignore)
g := creator()
Expect(m.Match(g)).To(BeTrue(), "creator %v", g.String())
Expect(m.Match(g)).To(BeTrue(), "creator: %v\ntried to ignore: %s",
g.String(), ignore)
Expect(m.Match(goroutine.Current())).To(BeFalse())
})

Expand Down

0 comments on commit bdc7803

Please sign in to comment.