From bdc7803e66e0db777db09edea3bb6e85df8c9d6d Mon Sep 17 00:00:00 2001 From: TheDiveO <6920158+thediveo@users.noreply.github.com> Date: Mon, 24 Jul 2023 14:07:17 +0200 Subject: [PATCH] fix: go 1.21 adding goroutine ID to creator+location (#685) tested on go1.21rc2 as of today's latest --- gleak/goroutine/goroutine.go | 4 ++++ gleak/ignoring_creator_test.go | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gleak/goroutine/goroutine.go b/gleak/goroutine/goroutine.go index e321ead56..d797ca924 100644 --- a/gleak/goroutine/goroutine.go +++ b/gleak/goroutine/goroutine.go @@ -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: @@ -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 } diff --git a/gleak/ignoring_creator_test.go b/gleak/ignoring_creator_test.go index 7b5f5cb72..f7ddbec2a 100644 --- a/gleak/ignoring_creator_test.go +++ b/gleak/ignoring_creator_test.go @@ -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()) })