From d1ac909e84c04f4326f620436b3894b3f5de0bd4 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Wed, 14 May 2025 21:43:26 +0800 Subject: [PATCH 1/3] sync/errgroup: PanicError.Error print stack trace Because it is useful to print the stack when a nil pointer dereference occurs. Fixes golang/go#73710 Change-Id: I106ea0bdd70c2a293f5ea889edef9b5ba9db2fbd Reviewed-on: https://go-review.googlesource.com/c/sync/+/672635 Reviewed-by: Damien Neil Auto-Submit: Damien Neil Auto-Submit: Alan Donovan Reviewed-by: Alan Donovan TryBot-Bypass: Damien Neil --- errgroup/errgroup.go | 5 +++-- errgroup/errgroup_test.go | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/errgroup/errgroup.go b/errgroup/errgroup.go index cfafed5..a6b6ad2 100644 --- a/errgroup/errgroup.go +++ b/errgroup/errgroup.go @@ -185,8 +185,9 @@ type PanicError struct { } func (p PanicError) Error() string { - // A Go Error method conventionally does not include a stack dump, so omit it - // here. (Callers who care can extract it from the Stack field.) + if len(p.Stack) > 0 { + return fmt.Sprintf("recovered from errgroup.Group: %v\n%s", p.Recovered, p.Stack) + } return fmt.Sprintf("recovered from errgroup.Group: %v", p.Recovered) } diff --git a/errgroup/errgroup_test.go b/errgroup/errgroup_test.go index 4684259..2165bb7 100644 --- a/errgroup/errgroup_test.go +++ b/errgroup/errgroup_test.go @@ -309,9 +309,9 @@ func TestPanic(t *testing.T) { if pe.Recovered != p { t.Fatalf("got %v, want %v", pe.Recovered, p) } - if !strings.Contains(string(pe.Stack), "TestPanic.func") { - t.Log(string(pe.Stack)) - t.Fatalf("stack trace incomplete") + if !strings.Contains(pe.Error(), "TestPanic.func") { + t.Log(pe.Error()) + t.Fatalf("stack trace incomplete, does not contain TestPanic.func") } }() g.Wait() From 1869c690bf11da5dd230e188d03a612a4a3f8ba6 Mon Sep 17 00:00:00 2001 From: Iliya Lyan <68940374+12ya@users.noreply.github.com> Date: Tue, 20 May 2025 23:05:19 +0000 Subject: [PATCH 2/3] all: replace deprecated ioutil Change-Id: I1beb9f5e759127a48c4e5ea0613a5a466886b7c5 GitHub-Last-Rev: 58038b6cdd6f289eb1e35e44a7c60ad150be3a6f GitHub-Pull-Request: golang/sync#28 Reviewed-on: https://go-review.googlesource.com/c/sync/+/674815 Reviewed-by: Alan Donovan LUCI-TryBot-Result: Go LUCI Reviewed-by: Sean Liao Auto-Submit: Alan Donovan Reviewed-by: Dmitri Shuralyov --- errgroup/errgroup_example_md5all_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/errgroup/errgroup_example_md5all_test.go b/errgroup/errgroup_example_md5all_test.go index 739b336..e2fc15b 100644 --- a/errgroup/errgroup_example_md5all_test.go +++ b/errgroup/errgroup_example_md5all_test.go @@ -8,7 +8,6 @@ import ( "context" "crypto/md5" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -69,7 +68,7 @@ func MD5All(ctx context.Context, root string) (map[string][md5.Size]byte, error) for i := 0; i < numDigesters; i++ { g.Go(func() error { for path := range paths { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return err } From 8a14946fb031f4bf6096242b5e6ae6f7316d47d8 Mon Sep 17 00:00:00 2001 From: xieyuschen Date: Wed, 28 May 2025 18:52:56 +0800 Subject: [PATCH 3/3] errgroup: remove duplicated comment Change-Id: I5cdcc5034ccd87b939a406693e97485553ab60fa Reviewed-on: https://go-review.googlesource.com/c/sync/+/676715 Reviewed-by: Dmitri Shuralyov Reviewed-by: Alan Donovan Auto-Submit: Alan Donovan LUCI-TryBot-Result: Go LUCI --- errgroup/errgroup.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/errgroup/errgroup.go b/errgroup/errgroup.go index a6b6ad2..cb6bb9a 100644 --- a/errgroup/errgroup.go +++ b/errgroup/errgroup.go @@ -76,10 +76,8 @@ func (g *Group) Wait() error { } // Go calls the given function in a new goroutine. -// The first call to Go must happen before a Wait. -// It blocks until the new goroutine can be added without the number of -// active goroutines in the group exceeding the configured limit. // +// The first call to Go must happen before a Wait. // It blocks until the new goroutine can be added without the number of // goroutines in the group exceeding the configured limit. //